mirror of
https://gitlab.com/gitlab-org/gitlab-foss.git
synced 2025-08-20 14:11:11 +00:00
Add latest changes from gitlab-org/gitlab@master
This commit is contained in:
@ -769,6 +769,54 @@ beforeEach(() => {
|
||||
});
|
||||
```
|
||||
|
||||
## Console warnings and errors in tests
|
||||
|
||||
Unexpected console warnings and errors are indicative of problems in our production code.
|
||||
We want our test environment to be strict, so your tests should fail when unexpected
|
||||
`console.error` or `console.warn` calls are made.
|
||||
|
||||
### Ignoring console messages from watcher
|
||||
|
||||
Since there's a lot of code outside of our control, there are some console messages that
|
||||
are ignored by default and will **not** fail a test if used. This list of ignored
|
||||
messages can be maintained where we call `setupConsoleWatcher`. Example:
|
||||
|
||||
```javascript
|
||||
setupConsoleWatcher({
|
||||
ignores: [
|
||||
...,
|
||||
// Any call to `console.error('Foo bar')` or `console.warn('Foo bar')` will be ignored by our console watcher.
|
||||
'Foo bar',
|
||||
// Use regex to allow for flexible message matching.
|
||||
/Lorem ipsum/,
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
If a specific test needs to ignore a specific message for a `describe` block, use the
|
||||
`ignoreConsoleMessages` helper near the top of the `describe`. This automatically
|
||||
calls `beforeAll` and `afterAll` to set up/teardown this set of ignored for the test
|
||||
context.
|
||||
|
||||
Use this sparingly and only if absolutely necessary for test maintainability. Example:
|
||||
|
||||
```javascript
|
||||
import { ignoreConsoleMessages } from 'helpers/console_watcher';
|
||||
|
||||
describe('foos/components/foo.vue', () => {
|
||||
describe('when blooped', () => {
|
||||
// Will not fail a test if `console.warn('Lorem ipsum')` is called
|
||||
ignoreConsoleMessages([
|
||||
/^Lorem ipsum/
|
||||
]);
|
||||
});
|
||||
|
||||
describe('default', () => {
|
||||
// Will fail a test if `console.warn('Lorem ipsum')` is called
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
## Factories
|
||||
|
||||
TBU
|
||||
|
Reference in New Issue
Block a user