Skip to content

Commit

Permalink
chore(ffe-account-selector-react): Rewrite tests to use Jest
Browse files Browse the repository at this point in the history
Replacing Mocha with Jest. I'm also fully utilizing Jest by kicking
out Sinon and Chai, replacing all of it with Jest.
  • Loading branch information
Henrik Hermansen committed Feb 8, 2018
1 parent 6d53ffa commit 389af74
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 197 deletions.
4 changes: 2 additions & 2 deletions packages/ffe-account-selector-react/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"overrides": [
{
"files": [ "src/**/*.test.js"],
"files": [ "src/**/*.spec.js"],
"env": {
"mocha": true
"jest": true
}
}
]
Expand Down
23 changes: 8 additions & 15 deletions packages/ffe-account-selector-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,20 @@
"name": "ffe-account-selector-react",
"version": "8.1.13",
"description": "Selector for bank accounts with autocomplete.",
"keywords": [
"ffe"
],
"keywords": ["ffe"],
"license": "UNLICENSED",
"author": "SpareBank 1",
"main": "lib/index.js",
"files": [
"less",
"lib",
"src",
"*.js"
],
"files": ["less", "lib", "src", "*.js"],
"repository": {
"type": "git",
"url": "***REMOVED***"
},
"scripts": {
"build": "babel -d lib/. --ignore=*.test.js src/.",
"lint": "eslint src/.",
"test": "mocha --require babel-core/register --require ./test-setup.js 'src/**/*.test.js'",
"test:watch": "npm test -- -w"
"test": "jest",
"test:watch": "jest --watch"
},
"dependencies": {
"classnames": "^2.2.5",
Expand All @@ -35,16 +28,16 @@
"react-custom-scrollbars": "^4.2.1"
},
"devDependencies": {
"chai": "^4.1.2",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"eslint": "^4.13.1",
"jsdom": "^11.5.1",
"mocha": "^4.1.0",
"sinon": "^4.1.3"
"jest": "^22.1.4"
},
"peerDependencies": {
"ffe-form": "4.x - 8.x",
"ffe-spinner": "2.x"
},
"jest": {
"setupTestFrameworkScriptFile": "./test-setup.js"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { mount } from 'enzyme';
import { expect } from 'chai';
import sinon from 'sinon';
import React from 'react';
import { mount } from 'enzyme';

import AccountSelector from './AccountSelector';
import Input from '../../subcomponents/input-field';
Expand Down Expand Up @@ -58,18 +56,18 @@ describe('<AccountSelector> methods', () => {
const component = mountAccountSelector();
component.instance().onInputChange('');

expect(
component.instance().baseSelector.props.suggestions.length,
).to.equal(3);
expect(component.instance().baseSelector.props.suggestions.length).toBe(
3,
);

component.setProps({ value: 'oo' });
expect(
component.instance().baseSelector.props.suggestions.length,
).to.equal(2);
expect(component.instance().baseSelector.props.suggestions.length).toBe(
2,
);
});

it('calls onSuggestionSelect with accounts[0] when the first item is selected', () => {
const onSuggestionSelectSpy = sinon.spy();
const onSuggestionSelectSpy = jest.fn();
const component = mountAccountSelector({
onSuggestionSelect: onSuggestionSelectSpy,
});
Expand All @@ -78,6 +76,6 @@ describe('<AccountSelector> methods', () => {
const suggestionListItem = component.find(SuggestionItem).first();
suggestionListItem.simulate('mousedown');

expect(onSuggestionSelectSpy.calledWith(accounts[0]));
expect(onSuggestionSelectSpy).toHaveBeenCalledWith(accounts[0]);
});
});
Loading

0 comments on commit 389af74

Please sign in to comment.