Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"private": true,
"description": "",
"main": "index.js",
"engines": {
"node": ">=7.0.0"
},
"scripts": {
"setup": "typings install",
"build": "npm run setup && npm run test && webpack",
Expand Down Expand Up @@ -36,7 +39,7 @@
"ts-jest": "^17.0.3",
"ts-loader": "^0.8.2",
"tslint": "^3.14.0",
"typescript": "2.0.3",
"typescript": "2.0.6",
"typings": "1.3.2",
"webpack": "^1.13.1",
"webpack-fail-plugin": "^1.0.5",
Expand Down
24 changes: 24 additions & 0 deletions src/components/__tests__/__snapshots__/counter_spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
exports[`components/Counter renders 1`] = `
<CounterComponent
counter={
Object {
"value": 0,
}
}
error=""
increment={[Function]}
isLoading={false}
isSaving={false}
label="a counter!"
load={[Function]}
save={[Function]}
store={
Object {
"dispatch": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
Symbol(observable): [Function],
}
} />
`;
44 changes: 13 additions & 31 deletions src/components/__tests__/counter_spec.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,31 @@
// tslint:disable-next-line no-unused-variable
import * as React from 'react'
import * as TestUtils from 'react-addons-test-utils'

import { createStore } from 'redux'
import { Provider } from 'react-redux'

import { Counter } from '../counter'
import { reducers } from '../../reducers'

describe('components/Counter', () => {

function renderElement (el: React.ReactElement<{}>) {
return TestUtils.renderIntoDocument(el) as React.Component<{}, {}>
}

function findComponentByType(root: React.Component<{}, {}>, type: any): React.Component<{}, {}> {
return TestUtils.findRenderedComponentWithType(root, type)
}

function setup (): React.Component<{}, {}> {
it('renders', () => {
const store = createStore(reducers)
const wrapper = renderElement(
<Provider store={store}>
<Counter label='a counter!' />
</Provider>
)
const counter = findComponentByType(wrapper, Counter)
return counter
}

it('starts at 0', () => {
const counter = setup()
const pre = TestUtils.findRenderedDOMComponentWithTag(counter, 'pre')
expect(JSON.parse(pre.textContent).counter.value).toEqual(0)
})

it('shows a label', () => {
const counter = setup()
const label = TestUtils.findRenderedDOMComponentWithTag(counter, 'legend')
expect(label.textContent).toEqual('a counter!')
const renderer = TestUtils.createRenderer()
expect(renderer.render(
<Counter label='a counter!' store={store} />
)).toMatchSnapshot()
})

describe('clicking "increment"', () => {
it('increments counter', () => {
const counter = setup()
const [ increment ] = TestUtils.scryRenderedDOMComponentsWithTag(counter, 'button')
const store = createStore(reducers)
const counter = TestUtils.renderIntoDocument(
<Counter label='a counter!' store={store} />
)
const [
increment,
] = TestUtils.scryRenderedDOMComponentsWithTag(counter, 'button')
TestUtils.Simulate.click(increment)
TestUtils.Simulate.click(increment)
TestUtils.Simulate.click(increment)
Expand Down