Skip to content

Commit fc69e25

Browse files
fix types verbosity on tests
1 parent 90b8093 commit fc69e25

File tree

8 files changed

+38
-25
lines changed

8 files changed

+38
-25
lines changed

spec/RecordedArguments.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,32 @@ test('records values and classifies them correctly', t => {
2020
const emptyArguments = RecordedArguments.from([])
2121
t.deepEqual(emptyArguments.value, [])
2222
t.is(emptyArguments.argumentsClass, 'plain')
23-
t.is(emptyArguments.hasNoArguments, false)
23+
t.is(emptyArguments.hasArguments(), true)
2424

2525
const primitivesOnlyArguments = RecordedArguments.from([1, 'Substitute', false, testSymbol, undefined, null, testFunc, {}])
2626
t.deepEqual(primitivesOnlyArguments.value, [1, 'Substitute', false, testSymbol, undefined, null, testFunc, {}])
2727
t.is(primitivesOnlyArguments.argumentsClass, 'plain')
28-
t.is(primitivesOnlyArguments.hasNoArguments, false)
28+
t.is(primitivesOnlyArguments.hasArguments(), true)
2929

3030
const anyArg = Arg.any('any')
3131
const withSingleArgumentArguments = RecordedArguments.from([1, 'Substitute', false, testSymbol, undefined, null, testFunc, {}, anyArg])
3232
t.deepEqual(withSingleArgumentArguments.value, [1, 'Substitute', false, testSymbol, undefined, null, testFunc, {}, anyArg])
3333
t.is(withSingleArgumentArguments.argumentsClass, 'with-predicate')
34-
t.is(withSingleArgumentArguments.hasNoArguments, false)
34+
t.is(withSingleArgumentArguments.hasArguments(), true)
3535

3636
const allArg = Arg.all()
3737
const allArgumentArguments = RecordedArguments.from([allArg])
3838
t.deepEqual(allArgumentArguments.value, [allArg])
3939
t.is(allArgumentArguments.argumentsClass, 'wildcard')
40-
t.is(allArgumentArguments.hasNoArguments, false)
40+
t.is(allArgumentArguments.hasArguments(), true)
4141
})
4242

4343
test('creates a valid instance for no arguments', t => {
4444
const args = RecordedArguments.none()
4545

4646
t.is(args.value, undefined)
4747
t.is(args.argumentsClass, undefined)
48-
t.is(args.hasNoArguments, true)
48+
t.is(args.hasArguments(), false)
4949
})
5050

5151
test('sorts correctly objects with RecordedArguments', t => {

spec/Recorder.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ test('indexes all records correctly', t => {
4040

4141
const nodeSet = recorder.indexedRecords.get(node.key)
4242
t.true(nodeSet instanceof RecordsSet)
43-
t.deepEqual([...nodeSet], [node])
43+
t.deepEqual([...nodeSet!], [node])
4444

4545
const otherNodeSet = recorder.indexedRecords.get(otherNode.key)
4646
t.true(otherNodeSet instanceof RecordsSet)
47-
t.deepEqual([...otherNodeSet], [otherNode, otherNodeDifferentInstance])
47+
t.deepEqual([...otherNodeSet!], [otherNode, otherNodeDifferentInstance])
4848
})
4949

5050
test('returns all sibling nodes', t => {
@@ -71,7 +71,7 @@ test('clears recorded nodes by a given filter function', t => {
7171

7272
recorder.clearRecords(n => n.key === otherNode.key)
7373
t.deepEqual([...recorder.records], [node])
74-
t.deepEqual([...recorder.indexedRecords.get(node.key)], [node])
74+
t.deepEqual([...recorder.indexedRecords.get(node.key)!], [node])
7575
t.is(recorder.indexedRecords.get(otherNode.key), undefined)
7676

7777
recorder.clearRecords(_ => true)

spec/regression/Arguments.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ test('should match any argument(s) using Arg.all', t => {
1818
t.true(Arg.all().matches(['string']))
1919
t.true(Arg.all().matches([true]))
2020
t.true(Arg.all().matches([false]))
21-
t.true(Arg.all().matches(null))
22-
t.true(Arg.all().matches(undefined))
21+
t.true(Arg.all().matches([null]))
22+
t.true(Arg.all().matches([undefined]))
2323
t.true(Arg.all().matches([1, 2]))
2424
t.true(Arg.all().matches(['string1', 'string2']))
2525
})
@@ -74,7 +74,7 @@ test('should match the type of the argument using Arg.any', t => {
7474

7575
t.false((<Argument<unknown>>Arg.any('string')).matches(1))
7676
t.false((<Argument<unknown>>Arg.any('number')).matches('string'))
77-
t.false(Arg.any('boolean').matches(null))
77+
t.false((<Argument<unknown>>Arg.any('boolean')).matches(null))
7878
t.false((<Argument<unknown>>Arg.any('object')).matches('foo'))
7979
t.false((<Argument<unknown>>Arg.any('array')).matches('bar'))
8080
t.false((<Argument<unknown>>Arg.any('function')).matches('foo'))

spec/regression/index.test.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import test from 'ava'
22

3-
import { Substitute, Arg } from '../../src'
4-
import { OmitProxyMethods, ObjectSubstitute } from '../../src/Transformations'
3+
import { Substitute, Arg, SubstituteOf } from '../../src'
54

65
class Dummy {
76

@@ -34,12 +33,12 @@ export class Example {
3433
}
3534

3635
bar(a: number, b?: number): number {
37-
return a + b || 0
36+
return a + (b ?? 0)
3837
}
3938
}
4039

4140
let instance: Example
42-
let substitute: ObjectSubstitute<Example>
41+
let substitute: SubstituteOf<Example>
4342

4443
function initialize() {
4544
instance = new Example()
@@ -69,21 +68,26 @@ test('class with method called \'received\' can be used for call count verificat
6968
test('class string field set received', t => {
7069
initialize()
7170

72-
substitute.v = undefined
73-
substitute.v = null
74-
substitute.v = 'hello'
75-
substitute.v = 'hello'
76-
substitute.v = 'world'
71+
const runLogic = (example: Example) => {
72+
example.v = undefined
73+
example.v = null
74+
example.v = 'hello'
75+
example.v = 'hello'
76+
example.v = 'world'
77+
}
78+
79+
runLogic(substitute)
80+
7781

7882
t.notThrows(() => substitute.received().v = 'hello')
7983
t.notThrows(() => substitute.received(5).v = Arg.any())
8084
t.notThrows(() => substitute.received().v = Arg.any())
8185
t.notThrows(() => substitute.received(2).v = 'hello')
82-
t.notThrows(() => substitute.received(2).v = Arg.is(x => x && x.indexOf('ll') > -1))
86+
t.notThrows(() => substitute.received(2).v = Arg.is(x => typeof x === 'string' && x.indexOf('ll') > -1))
8387

8488
t.throws(() => substitute.received(2).v = Arg.any())
8589
t.throws(() => substitute.received(1).v = Arg.any())
86-
t.throws(() => substitute.received(1).v = Arg.is(x => x && x.indexOf('ll') > -1))
90+
t.throws(() => substitute.received(1).v = Arg.is(x => typeof x === 'string' && x.indexOf('ll') > -1))
8791
t.throws(() => substitute.received(3).v = 'hello')
8892
})
8993

spec/regression/issues/36.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Service {
4242
await this._database.storeUpdates(updateData)
4343
}
4444
private getData(arg?: Key) {
45+
if (typeof arg === 'undefined') throw new TypeError('Key is undefined')
4546
return this._database.getUpdates(arg)
4647
}
4748
}

spec/regression/mimicks.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test('mimicks a method with Arg.all', t => {
4343
test('mimicks a method with optional arguments', t => {
4444
const calculator = Substitute.for<Calculator>()
4545
const multiplyOneArgMimicks = (a: number) => a * a
46-
const multiplyMimicks = (a: number, b?: number) => a * b
46+
const multiplyMimicks = (a: number, b?: number) => a * (b ?? 0)
4747

4848
calculator.multiply(0, Arg.is((b: number) => b > 10 && b < 20)).mimicks(multiplyMimicks)
4949
calculator.multiply(Arg.any('number'), Arg.is((b: number) => b === 2)).mimicks(multiplyMimicks)

spec/regression/received.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ test('getting a property twice correctly asserts the call count', t => {
6464

6565
test('setting a property twice correctly asserts the call count', t => {
6666
const calculator = Substitute.for<Calculator>()
67-
calculator.isEnabled = true
68-
calculator.isEnabled = true
67+
const runLogic = (calc: Calculator) => {
68+
calc.isEnabled = true
69+
calc.isEnabled = true
70+
}
71+
runLogic(calculator)
6972

7073
calculator.received(2).isEnabled = true
7174
calculator.received().isEnabled = true

spec/regression/returns.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ interface Calculator {
77
add(a: number, b: number): number
88
multiply(a: number, b?: number): number
99
clear(): void
10+
other(): Calculator
1011
getMemory(): Promise<number>
1112
viewResult(back?: number): number
1213
heavyOperation(...input: number[]): Promise<boolean>
1314
isEnabled: boolean
15+
isEnabled2: Calculator
1416
model: Promise<string>
1517
};
1618

1719
test('returns a primitive value for method with no arguments', t => {
1820
const calculator = Substitute.for<Calculator>()
1921
calculator.clear().returns()
22+
// calculator.add(1, 2).toExponential()
23+
// calculator.isEnabled2.viewResult().returns(3)
24+
// calculator.other().viewResult().returns(2)
2025

2126
t.is(calculator.clear(), void 0)
2227
})

0 commit comments

Comments
 (0)