-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
38 lines (32 loc) · 1.04 KB
/
test.js
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
// @flow
'use strict';
// The `jest` global exists when running in jest ¯\_(ツ)_/¯
const _jest = require('./');
const path = require('path');
const success = path.join(__dirname, 'fixtures', 'success');
const failure = path.join(__dirname, 'fixtures', 'failure');
function expectError() {
throw new Error('Expected Error');
}
test('success', () => {
return _jest.test({ rootDir: success }).then(res => {
expect(res.success).toBe(true);
expect(res.numFailedTestSuites).toBe(0);
expect(res.numPassedTestSuites).toBe(1);
});
});
test('failure', () => {
return _jest.test({ rootDir: failure }).then(expectError, err => {
expect(err.message).toContain('Tests failed');
expect(err.success).toBe(false);
expect(err.numFailedTestSuites).toBe(1);
expect(err.numPassedTestSuites).toBe(0);
});
});
test('default rootDir', () => {
jest.spyOn(process, 'cwd').mockImplementation(() => success);
return _jest.test().then(res => {
expect(process.cwd.mock.calls.length).toBeGreaterThan(0);
process.cwd.mockRestore();
});
});