Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tests] Reorg of karma tests and coverage setup, add jsdom, resolves #…
…4039, #3519 Removes isparta in favour of istanbul alpha with source map reconciliation support built in. Refactors several tests into shallow rendered unit tests. Adds JSDOM globals to the test suite so components dependent on DOM APIs can be effectively unit tested using enzyme.
- Loading branch information
1 parent
1f5762b
commit 5cf8044
Showing
37 changed files
with
597 additions
and
698 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
instrumentation: | ||
root: src | ||
default-excludes: true | ||
excludes: | ||
- "**/svg-icons/**" | ||
- "**/*.spec.js" | ||
extensions: | ||
- .js | ||
variable: __coverage__ | ||
es-modules: true | ||
include-all-sources: true | ||
reporting: | ||
print: summary | ||
reports: | ||
- lcov | ||
dir: ./test/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
--- | ||
language: node_js | ||
node_js: | ||
- "stable" | ||
sudo: false | ||
cache: | ||
directories: | ||
- node_modules | ||
script: | ||
- npm run lint | ||
- npm test | ||
- npm run test:coverage | ||
- ./node_modules/.bin/codecov | ||
- npm run test:karma | ||
- cd packages/material-ui-codemod && npm install && npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* eslint-env mocha */ | ||
import React from 'react'; | ||
import {shallow} from 'enzyme'; | ||
import {mount} from 'enzyme'; | ||
import {assert} from 'chai'; | ||
import Checkbox from './Checkbox'; | ||
import getMuiTheme from '../styles/getMuiTheme'; | ||
|
||
describe('<Checkbox />', () => { | ||
/* eslint-disable max-len */ | ||
const muiTheme = getMuiTheme(); | ||
const shallowWithContext = (node) => shallow(node, {context: {muiTheme}}); | ||
const mountWithContext = (node) => mount(node, {context: {muiTheme}}); | ||
|
||
it('should display checkmark when checked by default', () => { | ||
const wrapper = shallowWithContext( | ||
<Checkbox defaultChecked={true} /> | ||
); | ||
|
||
const enhancedSwitch = wrapper.find('EnhancedSwitch'); | ||
const svgs = wrapper.prop('switchElement').props.children; | ||
const checkMarkNode = shallow(svgs[1]); | ||
|
||
assert.ok(enhancedSwitch.prop('switched')); | ||
assert.ok(checkMarkNode.is('ToggleCheckBox')); | ||
assert.strictEqual(checkMarkNode.props().style.opacity, 1); | ||
}); | ||
|
||
|
||
it('should NOT display checkmark when not checked by default', () => { | ||
const wrapper = shallowWithContext( | ||
<Checkbox defaultChecked={false} /> | ||
); | ||
|
||
const enhancedSwitch = wrapper.find('EnhancedSwitch'); | ||
const svgs = wrapper.prop('switchElement').props.children; | ||
const checkMarkNode = shallow(svgs[1]); | ||
|
||
assert.notOk(enhancedSwitch.prop('switched')); | ||
assert.ok(checkMarkNode.is('ToggleCheckBox')); | ||
assert.strictEqual(checkMarkNode.props().style.opacity, 0); | ||
}); | ||
|
||
|
||
describe('when initially unchecked', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = mountWithContext( | ||
<Checkbox defaultChecked={false} /> | ||
); | ||
}); | ||
|
||
it('should display checkmark when clicked once', () => { | ||
const input = wrapper.find('input'); | ||
input.node.checked = !input.node.checked; | ||
input.simulate('change'); | ||
const enhancedSwitch = wrapper.find('EnhancedSwitch'); | ||
assert.ok(enhancedSwitch.prop('switched')); | ||
}); | ||
|
||
|
||
it('should NOT display checkmark when clicked twice', () => { | ||
const input = wrapper.find('input'); | ||
input.node.checked = !input.node.checked; | ||
input.simulate('change'); | ||
input.node.checked = !input.node.checked; | ||
input.simulate('change'); | ||
const enhancedSwitch = wrapper.find('EnhancedSwitch'); | ||
assert.notOk(enhancedSwitch.prop('switched')); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.