ensure we expect the correct amount of assertions

It is a bit of noise but it will ensure that we don't have false
positives. For example when you have the following code:

```js
it('should fail', () => {
  return promise.catch((err) => {
    expect(err).toBeInstanceOf(Error)
  });
});
```

You would expect that the test passes because we have an expect in the
`.catch` block. However if the promise just resolves it means that no
assertions are executed and the test is considered successful. So in
this case it will _also_ call but for the incorrect reasons!
This commit is contained in:
Robin Malfait 2020-08-22 00:06:47 +02:00
parent 3bf6348523
commit f15cace373
No known key found for this signature in database
GPG key ID: 92F53D68B9041AFE

View file

@ -41,6 +41,8 @@ function run(
test('it copies class declarations into itself', () => {
const output = '.a { color: red; } .b { color: red; }'
expect.assertions(2)
return run('.a { color: red; } .b { @apply a; }').then(result => {
expect(result.css).toEqual(output)
expect(result.warnings().length).toBe(0)
@ -105,6 +107,8 @@ test('selectors with invalid characters do not need to be manually escaped', ()
.b { color: red; }
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -122,6 +126,8 @@ test('it removes important from applied classes by default', () => {
.b { color: red; }
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -139,6 +145,8 @@ test('applied rules can be made !important', () => {
.b { color: red !important; }
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -155,12 +163,16 @@ test('cssnext custom property sets are no longer supported', () => {
}
`
expect.assertions(1)
return run(input).catch(e => {
expect(e).toMatchObject({ name: 'CssSyntaxError' })
})
})
test('it fails if the class does not exist', () => {
expect.assertions(1)
return run('.b { @apply a; }').catch(e => {
expect(e).toMatchObject({ name: 'CssSyntaxError' })
})
@ -186,6 +198,8 @@ test('applying classes that are defined in a media query is supported', () => {
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(output)
expect(result.warnings().length).toBe(0)
@ -225,6 +239,8 @@ test('applying classes that are used in a media query is supported', () => {
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(output)
expect(result.warnings().length).toBe(0)
@ -252,6 +268,8 @@ test('it matches classes that include pseudo-selectors', () => {
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(output)
expect(result.warnings().length).toBe(0)
@ -288,6 +306,8 @@ test('it matches classes that have multiple rules', () => {
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(output)
expect(result.warnings().length).toBe(0)
@ -320,6 +340,8 @@ test('applying a class that appears multiple times in one selector', () => {
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(output)
expect(result.warnings().length).toBe(0)
@ -335,6 +357,8 @@ test('you can apply utility classes that do not actually exist as long as they w
.foo { margin-top: 1rem; }
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -347,6 +371,8 @@ test('the shadow lookup is only used if no @tailwind rules were in the source tr
.foo { @apply mt-4; }
`
expect.assertions(1)
return run(input).catch(e => {
expect(e).toMatchObject({ name: 'CssSyntaxError' })
})
@ -377,6 +403,8 @@ test('you can apply a class that is defined in multiple rules', () => {
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -397,6 +425,8 @@ test('you can apply a class that is defined in a media query', () => {
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -415,6 +445,8 @@ test('you can apply pseudo-class variant utilities', () => {
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -435,6 +467,8 @@ test('you can apply responsive pseudo-class variant utilities', () => {
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -473,6 +507,8 @@ test('you can apply the container component', () => {
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -504,6 +540,8 @@ test('classes are applied according to CSS source order, not apply order', () =>
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -534,6 +572,8 @@ test('you can apply utilities with multi-class selectors like group-hover varian
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -564,6 +604,8 @@ test('you can apply classes recursively', () => {
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -599,6 +641,8 @@ test('applied classes are always inserted before subsequent declarations in the
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -630,6 +674,8 @@ test('adjacent rules are collapsed after being applied', () => {
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -678,6 +724,8 @@ test('applying a class applies all instances of that class, even complex selecto
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -711,6 +759,8 @@ test('you can apply classes to rules within at-rules', () => {
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -734,6 +784,8 @@ describe('using apply with the prefix option', () => {
},
])
expect.assertions(2)
return run(input, config).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -758,6 +810,8 @@ describe('using apply with the prefix option', () => {
},
])
expect.assertions(2)
return run(input, config).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -776,6 +830,8 @@ describe('using apply with the prefix option', () => {
},
])
expect.assertions(1)
return run(input, config).catch(e => {
expect(e).toMatchObject({ name: 'CssSyntaxError' })
})
@ -799,6 +855,8 @@ describe('using apply with the prefix option', () => {
},
])
expect.assertions(2)
return run(input, config).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -823,6 +881,8 @@ describe('using apply with the prefix option', () => {
},
])
expect.assertions(2)
return run(input, config).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -868,6 +928,8 @@ describe('using apply with the prefix option', () => {
},
])
expect.assertions(2)
return run(input, config).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -891,6 +953,8 @@ describe('using apply with the prefix option', () => {
},
])
expect.assertions(2)
return run(input, config).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
@ -919,6 +983,8 @@ test('you can apply utility classes when a selector is used for the important op
},
])
expect.assertions(2)
return run(input, config).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)