Skip to content

Commit

Permalink
fix tests due to refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
notanengineercom committed Oct 7, 2022
1 parent 66e5616 commit 59e78af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
21 changes: 10 additions & 11 deletions spec/ClearSubstitute.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import test from 'ava'

import { Substitute, SubstituteOf } from '../src'
import { SubstituteBase } from '../src/SubstituteBase'
import { SubstituteNode } from '../src/SubstituteNode'

interface Calculator {
Expand All @@ -12,7 +11,7 @@ interface Calculator {
}

type InstanceReturningSubstitute<T> = SubstituteOf<T> & {
[SubstituteBase.instance]: Substitute
[SubstituteNode.instance]: SubstituteNode
}

test('clears everything on a substitute', t => {
Expand All @@ -21,8 +20,8 @@ test('clears everything on a substitute', t => {
calculator.received().add(1, 1)
calculator.clearSubstitute()

t.is(calculator[Substitute.instance].recorder.records.size, 0)
t.is(calculator[Substitute.instance].recorder.indexedRecords.size, 0)
t.is(calculator[SubstituteNode.instance].recorder.records.size, 0)
t.is(calculator[SubstituteNode.instance].recorder.indexedRecords.size, 0)

t.throws(() => calculator.received().add(1, 1))

Expand All @@ -31,8 +30,8 @@ test('clears everything on a substitute', t => {
calculator.received().add(1, 1)
calculator.clearSubstitute('all')

t.is(calculator[Substitute.instance].recorder.records.size, 0)
t.is(calculator[Substitute.instance].recorder.indexedRecords.size, 0)
t.is(calculator[SubstituteNode.instance].recorder.records.size, 0)
t.is(calculator[SubstituteNode.instance].recorder.indexedRecords.size, 0)

t.throws(() => calculator.received().add(1, 1))
})
Expand All @@ -43,8 +42,8 @@ test('clears received calls on a substitute', t => {
calculator.add(1, 1).returns(2)
calculator.clearSubstitute('receivedCalls')

t.is(calculator[Substitute.instance].recorder.records.size, 2)
t.is(calculator[Substitute.instance].recorder.indexedRecords.size, 2)
t.is(calculator[SubstituteNode.instance].recorder.records.size, 2)
t.is(calculator[SubstituteNode.instance].recorder.indexedRecords.size, 2)

t.throws(() => calculator.received().add(1, 1))
t.is(calculator.add(1, 1), 2)
Expand All @@ -56,10 +55,10 @@ test('clears return values on a substitute', t => {
calculator.add(1, 1).returns(2)
calculator.clearSubstitute('substituteValues')

t.is(calculator[Substitute.instance].recorder.records.size, 2)
t.is(calculator[Substitute.instance].recorder.indexedRecords.size, 2)
t.is(calculator[SubstituteNode.instance].recorder.records.size, 2)
t.is(calculator[SubstituteNode.instance].recorder.indexedRecords.size, 2)

t.notThrows(() => calculator.received().add(1, 1))
// @ts-expect-error
t.true(calculator.add(1, 1)[SubstituteBase.instance] instanceof SubstituteNode)
t.true(calculator.add(1, 1)[SubstituteNode.instance] instanceof SubstituteNode)
})
8 changes: 4 additions & 4 deletions spec/Recorder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const otherNode = nodeFactory('otherNode')
const otherNodeDifferentInstance = nodeFactory('otherNode')

test('adds all records once only', t => {
const recorder = new Recorder()
const recorder = Recorder.withIdentityProperty<SubstituteNodeBase>('key')
recorder.addRecord(node)
recorder.addRecord(node)
recorder.addRecord(otherNode)
Expand All @@ -28,7 +28,7 @@ test('adds all records once only', t => {
})

test('indexes all records correctly', t => {
const recorder = new Recorder()
const recorder = Recorder.withIdentityProperty<SubstituteNodeBase>('key')
recorder.addIndexedRecord(node)
recorder.addIndexedRecord(node)
recorder.addIndexedRecord(otherNode)
Expand All @@ -48,7 +48,7 @@ test('indexes all records correctly', t => {
})

test('returns all sibling nodes', t => {
const recorder = new Recorder()
const recorder = Recorder.withIdentityProperty<SubstituteNodeBase>('key')
recorder.addIndexedRecord(node)
recorder.addIndexedRecord(otherNode)
recorder.addIndexedRecord(otherNodeDifferentInstance)
Expand All @@ -64,7 +64,7 @@ test('returns all sibling nodes', t => {
})

test('clears recorded nodes by a given filter function', t => {
const recorder = new Recorder()
const recorder = Recorder.withIdentityProperty<SubstituteNodeBase>('key')
recorder.addIndexedRecord(node)
recorder.addIndexedRecord(otherNode)
recorder.addIndexedRecord(otherNodeDifferentInstance)
Expand Down
2 changes: 1 addition & 1 deletion spec/regression/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class Example {
}

let instance: Example
let substitute: ObjectSubstitute<OmitProxyMethods<Example>, Example>
let substitute: ObjectSubstitute<Example>

function initialize() {
instance = new Example()
Expand Down

0 comments on commit 59e78af

Please sign in to comment.