Skip to content

Instantly share code, notes, and snippets.

View pahund's full-sized avatar

Patrick Hund pahund

View GitHub Profile
@pahund
pahund / thisWontWork.test.js
Created May 27, 2017 16:21
Using chai assertions with Jest's expect – this doesn't work because of short-hand arrow function
describe('the result', () => it('is boolean value false', () =>
expect(result).to.be.a('boolean').and.equal(false)
));
@pahund
pahund / setup.js
Created May 25, 2017 12:48
Creating a global variable for chai.expect
const chai = require('chai');
const sinonChai = require('sinon-chai');
const chaiAsPromised = require('chai-as-promised');
const chaiEnzyme = require('chai-enzyme');
chai.use(sinonChai);
chai.use(chaiAsPromised);
chai.use(chaiEnzyme());
global.chaiExpect = chai.expect;
@pahund
pahund / externalsConverters.test.js
Created May 25, 2017 11:38
Chai assertion after running through the Jest code mod, fixed manually
describe('When I call bool', () =>
describe('with “TRUE”', () => {
let result;
beforeEach(() => result = bool('TRUE'));
describe('the result', () => it('is boolean value true', () => {
expect(typeof result).toBe('boolean');
expect(result).toBe(true);
}));
})
);
@pahund
pahund / externalsConvertersTest.js
Created May 25, 2017 11:20
Original chai assertion before running through the Jest code mod
describe('When I call bool', () =>
describe('with “TRUE”', () => {
let result;
beforeEach(() => result = bool('TRUE'));
describe('the result', () => it('is boolean value true', () =>
result.should.be.a('boolean').and.equal(true)
));
})
);
@pahund
pahund / externalsConverters.test.js
Created May 25, 2017 11:17
Chai assertion after running through the Jest code mod
describe('When I call bool', () =>
describe('with “TRUE”', () => {
let result;
beforeEach(() => result = bool('TRUE'));
describe('the result', () => it('is boolean value true', () =>
expect(result).be.a('boolean').toBe(true)
));
})
);
@pahund
pahund / chai-example.test.js
Last active May 25, 2017 11:09
Example of Chai BDD assertion
describe('the best flavor', () => it('is grapefruit', () =>
bestLaCroixFlavor().should.be('grapefruit')
));
@pahund
pahund / jest-example.test.js
Last active May 25, 2017 10:41
Example for usage of expect in Jest (taken from Jest API docs)
test('the best flavor is grapefruit', () =>
expect(bestLaCroixFlavor()).toBe('grapefruit')
);
@pahund
pahund / .eslintrc
Last active May 25, 2017 10:44
Adding the ESLint Jest plugin
"env": {
"jest": true
}
@pahund
pahund / styleMock.js
Created May 25, 2017 08:36
Empty module for mocking Sass modules with Jest
module.exports = {};
@pahund
pahund / package.json
Last active May 25, 2017 11:07
Setting up a Jest mock for React components styled with Sass
"jest": {
"moduleNameMapper": {
"\\.scss$": "<rootDir>/test/styleMock.js"
}
}