@@ -20,7 +20,6 @@ ruleTester.run('no-standalone-expect', rule, {
20
20
'it("an it", () => expect(1).toBe(1))' ,
21
21
'const func = function(){ expect(1).toBe(1); };' ,
22
22
'const func = () => expect(1).toBe(1);' ,
23
- 'expect.hasAssertions()' ,
24
23
'{}' ,
25
24
'it.each([1, true])("trues", value => { expect(value).toBe(true); });' ,
26
25
'it.each([1, true])("trues", value => { expect(value).toBe(true); }); it("an it", () => { expect(1).toBe(1) });' ,
@@ -59,27 +58,31 @@ ruleTester.run('no-standalone-expect', rule, {
59
58
] ,
60
59
invalid : [
61
60
{
62
- code : "(() => {})('testing', () => expect(true))" ,
63
- errors : [ { endColumn : 41 , column : 29 , messageId : 'unexpectedExpect' } ] ,
61
+ code : "(() => {})('testing', () => expect(true).toBe(false))" ,
62
+ errors : [ { endColumn : 53 , column : 29 , messageId : 'unexpectedExpect' } ] ,
63
+ } ,
64
+ {
65
+ code : 'expect.hasAssertions()' ,
66
+ errors : [ { endColumn : 23 , column : 1 , messageId : 'unexpectedExpect' } ] ,
64
67
} ,
65
68
{
66
69
code : dedent `
67
70
describe('scenario', () => {
68
71
const t = Math.random() ? it.only : it;
69
- t('testing', () => expect(true));
72
+ t('testing', () => expect(true).toBe(false) );
70
73
});
71
74
` ,
72
- errors : [ { endColumn : 34 , column : 22 , messageId : 'unexpectedExpect' } ] ,
75
+ errors : [ { endColumn : 46 , column : 22 , messageId : 'unexpectedExpect' } ] ,
73
76
} ,
74
77
{
75
78
code : dedent `
76
79
describe('scenario', () => {
77
80
const t = Math.random() ? it.only : it;
78
- t('testing', () => expect(true));
81
+ t('testing', () => expect(true).toBe(false) );
79
82
});
80
83
` ,
81
84
options : [ { additionalTestBlockFunctions : undefined } ] ,
82
- errors : [ { endColumn : 34 , column : 22 , messageId : 'unexpectedExpect' } ] ,
85
+ errors : [ { endColumn : 46 , column : 22 , messageId : 'unexpectedExpect' } ] ,
83
86
} ,
84
87
{
85
88
code : dedent `
@@ -91,7 +94,7 @@ ruleTester.run('no-standalone-expect', rule, {
91
94
expect(a + b).toBe(expected);
92
95
});
93
96
` ,
94
- errors : [ { endColumn : 16 , column : 3 , messageId : 'unexpectedExpect' } ] ,
97
+ errors : [ { endColumn : 31 , column : 3 , messageId : 'unexpectedExpect' } ] ,
95
98
} ,
96
99
{
97
100
code : dedent `
@@ -104,7 +107,7 @@ ruleTester.run('no-standalone-expect', rule, {
104
107
});
105
108
` ,
106
109
options : [ { additionalTestBlockFunctions : [ 'each' ] } ] ,
107
- errors : [ { endColumn : 16 , column : 3 , messageId : 'unexpectedExpect' } ] ,
110
+ errors : [ { endColumn : 31 , column : 3 , messageId : 'unexpectedExpect' } ] ,
108
111
} ,
109
112
{
110
113
code : dedent `
@@ -117,43 +120,48 @@ ruleTester.run('no-standalone-expect', rule, {
117
120
});
118
121
` ,
119
122
options : [ { additionalTestBlockFunctions : [ 'test' ] } ] ,
120
- errors : [ { endColumn : 16 , column : 3 , messageId : 'unexpectedExpect' } ] ,
123
+ errors : [ { endColumn : 31 , column : 3 , messageId : 'unexpectedExpect' } ] ,
121
124
} ,
122
125
{
123
126
code : 'describe("a test", () => { expect(1).toBe(1); });' ,
124
- errors : [ { endColumn : 37 , column : 28 , messageId : 'unexpectedExpect' } ] ,
127
+ errors : [ { endColumn : 45 , column : 28 , messageId : 'unexpectedExpect' } ] ,
125
128
} ,
126
129
{
127
130
code : 'describe("a test", () => expect(1).toBe(1));' ,
128
- errors : [ { endColumn : 35 , column : 26 , messageId : 'unexpectedExpect' } ] ,
131
+ errors : [ { endColumn : 43 , column : 26 , messageId : 'unexpectedExpect' } ] ,
129
132
} ,
130
133
{
131
134
code : 'describe("a test", () => { const func = () => { expect(1).toBe(1); }; expect(1).toBe(1); });' ,
132
- errors : [ { endColumn : 80 , column : 71 , messageId : 'unexpectedExpect' } ] ,
135
+ errors : [ { endColumn : 88 , column : 71 , messageId : 'unexpectedExpect' } ] ,
133
136
} ,
134
137
{
135
138
code : 'describe("a test", () => { it(() => { expect(1).toBe(1); }); expect(1).toBe(1); });' ,
136
- errors : [ { endColumn : 72 , column : 63 , messageId : 'unexpectedExpect' } ] ,
139
+ errors : [ { endColumn : 80 , column : 63 , messageId : 'unexpectedExpect' } ] ,
137
140
} ,
138
141
{
139
142
code : 'expect(1).toBe(1);' ,
140
- errors : [ { endColumn : 10 , column : 1 , messageId : 'unexpectedExpect' } ] ,
141
- } ,
142
- {
143
- code : 'expect(1).toBe' ,
144
- errors : [ { endColumn : 10 , column : 1 , messageId : 'unexpectedExpect' } ] ,
143
+ errors : [ { endColumn : 18 , column : 1 , messageId : 'unexpectedExpect' } ] ,
145
144
} ,
146
145
{
147
146
code : '{expect(1).toBe(1)}' ,
148
- errors : [ { endColumn : 11 , column : 2 , messageId : 'unexpectedExpect' } ] ,
147
+ errors : [ { endColumn : 19 , column : 2 , messageId : 'unexpectedExpect' } ] ,
149
148
} ,
150
149
{
151
150
code : 'it.each([1, true])("trues", value => { expect(value).toBe(true); }); expect(1).toBe(1);' ,
152
- errors : [ { endColumn : 79 , column : 70 , messageId : 'unexpectedExpect' } ] ,
151
+ errors : [ { endColumn : 87 , column : 70 , messageId : 'unexpectedExpect' } ] ,
153
152
} ,
154
153
{
155
154
code : 'describe.each([1, true])("trues", value => { expect(value).toBe(true); });' ,
156
- errors : [ { endColumn : 59 , column : 46 , messageId : 'unexpectedExpect' } ] ,
155
+ errors : [ { endColumn : 70 , column : 46 , messageId : 'unexpectedExpect' } ] ,
156
+ } ,
157
+ {
158
+ code : dedent `
159
+ import { expect as pleaseExpect } from '@jest/globals';
160
+
161
+ describe("a test", () => { pleaseExpect(1).toBe(1); });
162
+ ` ,
163
+ parserOptions : { sourceType : 'module' } ,
164
+ errors : [ { endColumn : 51 , column : 28 , messageId : 'unexpectedExpect' } ] ,
157
165
} ,
158
166
] ,
159
167
} ) ;
0 commit comments