File tree Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -8,11 +8,13 @@ readability.
88
99This autofixable rule aims to ensure usage of ` .toBeEmptyDOMElement() `
1010
11- Examples of ** incorrect ** code for this rule:
11+ Examples of ** correct ** code for this rule:
1212
1313``` js
1414expect (element .innerHTML ).toBe (" foo" );
15+ expect (element .innerHTML ).toBe (foo);
1516expect (element .innerHTML ).not .toBe (" foo" );
17+ expect (element .innerHTML ).not .toBe (foo);
1618expect (element .firstChild ).toBe (" foo" );
1719expect (element .firstChild ).not .toBe (" foo" );
1820expect (getByText (" foo" ).innerHTML ).toBe (" foo" );
@@ -28,7 +30,7 @@ expect(element.firstChild !== null).toBe(false);
2830expect (element .firstChild === null ).toBe (false );
2931```
3032
31- Examples of ** correct ** code for this rule:
33+ Examples of ** incorrect ** code for this rule:
3234
3335``` js
3436expect (element .innerHTML ).toBe (" " );
Original file line number Diff line number Diff line change @@ -18,7 +18,9 @@ const ruleTester = new RuleTester();
1818ruleTester . run ( "prefer-empty" , rule , {
1919 valid : [
2020 `expect(element.innerHTML).toBe('foo')` ,
21+ `expect(element.innerHTML).toBe(foo)` ,
2122 `expect(element.innerHTML).not.toBe('foo')` ,
23+ `expect(element.innerHTML).not.toBe(foo)` ,
2224 `expect(element.firstChild).toBe('foo')` ,
2325 `expect(element.firstChild).not.toBe('foo')` ,
2426 `expect(getByText("foo").innerHTML).toBe('foo')` ,
Original file line number Diff line number Diff line change @@ -55,7 +55,8 @@ export const create = (context) => ({
5555 [ `MemberExpression[property.name = 'innerHTML'][parent.callee.name = 'expect'][parent.parent.property.name = /toBe$|to(Strict)?Equal/]` ] (
5656 node
5757 ) {
58- if ( node . parent . parent . parent . arguments [ 0 ] . value ) {
58+ const args = node . parent . parent . parent . arguments [ 0 ] ;
59+ if ( args . value || args . name ) {
5960 return ;
6061 }
6162
@@ -72,7 +73,8 @@ export const create = (context) => ({
7273 [ `MemberExpression[property.name='innerHTML'][parent.parent.property.name='not'][parent.parent.parent.property.name=/toBe$|to(Strict)?Equal$/][parent.parent.object.callee.name='expect']` ] (
7374 node
7475 ) {
75- if ( node . parent . parent . parent . parent . arguments [ 0 ] . value ) {
76+ const args = node . parent . parent . parent . parent . arguments [ 0 ] ;
77+ if ( args . value || args . name ) {
7678 return ;
7779 }
7880
You can’t perform that action at this time.
0 commit comments