/
prefer-to-be-object.test.ts
72 lines (70 loc) · 2.31 KB
/
prefer-to-be-object.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { test, describe } from 'vitest'
import ruleTester from '../utils/tester'
import rule, { RULE_NAME } from './prefer-to-be-object'
const messageId = 'preferToBeObject'
describe(RULE_NAME, () => {
test(RULE_NAME, () => {
ruleTester.run(RULE_NAME, rule, {
valid: [
'expectTypeOf.hasAssertions',
'expectTypeOf.hasAssertions()',
'expectTypeOf',
'expectTypeOf().not',
'expectTypeOf().toBe',
'expectTypeOf().toBe(true)',
'expectTypeOf({}).toBe(true)',
'expectTypeOf({}).toBeObject()',
'expectTypeOf({}).not.toBeObject()',
'expectTypeOf([] instanceof Array).not.toBeObject()',
'expectTypeOf({}).not.toBeInstanceOf(Array)'
],
invalid: [
{
code: 'expectTypeOf(({} instanceof Object)).toBeTruthy();',
output: 'expectTypeOf(({})).toBeObject();',
errors: [{ messageId: 'preferToBeObject', column: 38, line: 1 }]
},
{
code: 'expectTypeOf({} instanceof Object).toBeTruthy();',
output: 'expectTypeOf({}).toBeObject();',
errors: [{ messageId, column: 36, line: 1 }]
},
{
code: 'expectTypeOf({} instanceof Object).not.toBeTruthy();',
output: 'expectTypeOf({}).not.toBeObject();',
errors: [{ messageId, column: 40, line: 1 }]
},
{
code: 'expectTypeOf({} instanceof Object).toBeFalsy();',
output: 'expectTypeOf({}).not.toBeObject();',
errors: [{ messageId, column: 36, line: 1 }]
},
{
code: 'expectTypeOf({} instanceof Object).not.toBeFalsy();',
output: 'expectTypeOf({}).toBeObject();',
errors: [{ messageId, column: 40, line: 1 }]
},
{
code: 'expectTypeOf({}).toBeInstanceOf(Object);',
output: 'expectTypeOf({}).toBeObject();',
errors: [{ messageId, column: 18, line: 1 }]
},
{
code: 'expectTypeOf({}).not.toBeInstanceOf(Object);',
output: 'expectTypeOf({}).not.toBeObject();',
errors: [{ messageId, column: 22, line: 1 }]
},
{
code: 'expectTypeOf(requestValues()).resolves.toBeInstanceOf(Object);',
output: 'expectTypeOf(requestValues()).resolves.toBeObject();',
errors: [{ messageId, column: 40, line: 1 }]
},
{
code: 'expectTypeOf(queryApi()).resolves.not.toBeInstanceOf(Object);',
output: 'expectTypeOf(queryApi()).resolves.not.toBeObject();',
errors: [{ messageId, column: 39, line: 1 }]
}
]
})
})
})