Browse Source
* Add jest and enzyme * Add test for connected component * fix lint * update travis * Add e2e test * fix ci * Add e2e test * update travis.yml * Fix global jasmine timeout * update test scripts * fix jest glob patterns * short timeout * fix travis * uitest => unit-test * Add ls in travis.yml * use electron on travis https://github.com/segmentio/nightmare/issues/313#issuecomment-152274351 * clear travis.yml * change setup file name * ignore coverage * unit-test => unit * remove helpers/visit * update test script * clean up test scripts * ignore test casepull/13/head
committed by
GitHub
14 changed files with 176 additions and 13 deletions
@ -0,0 +1,9 @@ |
|||||
|
import Nightmare from 'nightmare'; |
||||
|
|
||||
|
describe('Homepage', () => { |
||||
|
it('it should have logo text', async () => { |
||||
|
const page = Nightmare().goto('http://localhost:8000'); |
||||
|
const text = await page.evaluate(() => document.body.innerHTML).end(); |
||||
|
expect(text).toContain('<h1>Ant Design Pro</h1>'); |
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,27 @@ |
|||||
|
import Nightmare from 'nightmare'; |
||||
|
|
||||
|
describe('Login', () => { |
||||
|
let page; |
||||
|
beforeEach(() => { |
||||
|
page = Nightmare(); |
||||
|
page.goto('http://localhost:8000/#/user/login'); |
||||
|
}); |
||||
|
|
||||
|
it('should login with failure', async () => { |
||||
|
await page.type('#userName', 'mockuser') |
||||
|
.type('#password', 'wrong_password') |
||||
|
.click('button[type="submit"]') |
||||
|
.wait('.ant-alert-error') // should display error
|
||||
|
.end(); |
||||
|
}); |
||||
|
|
||||
|
xit('should login successfully', async () => { |
||||
|
const text = await page.type('#userName', 'admin') |
||||
|
.type('#password', '888888') |
||||
|
.click('button[type="submit"]') |
||||
|
.wait('.ant-layout-sider h1') // should display error
|
||||
|
.evaluate(() => document.body.innerHTML) |
||||
|
.end(); |
||||
|
expect(text).toContain('<h1>Ant Design Pro</h1>'); |
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,10 @@ |
|||||
|
import React from 'react'; |
||||
|
import { shallow } from 'enzyme'; |
||||
|
import Dashboard from './Dashboard'; |
||||
|
|
||||
|
it('renders Dashboard', () => { |
||||
|
const wrapper = shallow( |
||||
|
<Dashboard.WrappedComponent user={{ list: [] }} /> |
||||
|
); |
||||
|
expect(wrapper.find('Table').props().dataSource).toEqual([]); |
||||
|
}); |
||||
@ -0,0 +1,9 @@ |
|||||
|
import React from 'react'; |
||||
|
import { shallow } from 'enzyme'; |
||||
|
import Success from './Success'; |
||||
|
|
||||
|
it('renders with Result', () => { |
||||
|
const wrapper = shallow(<Success />); |
||||
|
expect(wrapper.find('Result').length).toBe(1); |
||||
|
expect(wrapper.find('Result').prop('type')).toBe('success'); |
||||
|
}); |
||||
@ -0,0 +1 @@ |
|||||
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000; |
||||
@ -0,0 +1,32 @@ |
|||||
|
const { spawn } = require('child_process'); |
||||
|
const { kill } = require('cross-port-killer'); |
||||
|
|
||||
|
const env = Object.create(process.env); |
||||
|
env.BROWSER = 'none'; |
||||
|
const startServer = spawn('npm', ['start'], { |
||||
|
env, |
||||
|
}); |
||||
|
|
||||
|
startServer.stderr.on('data', (data) => { |
||||
|
// eslint-disable-next-line
|
||||
|
console.log(data); |
||||
|
}); |
||||
|
|
||||
|
startServer.on('exit', () => { |
||||
|
kill(process.env.PORT || 8000); |
||||
|
}); |
||||
|
|
||||
|
// eslint-disable-next-line
|
||||
|
console.log('Starting development server for e2e tests...'); |
||||
|
startServer.stdout.on('data', (data) => { |
||||
|
if (data.toString().indexOf('The app is running at') >= 0) { |
||||
|
// eslint-disable-next-line
|
||||
|
console.log('Development server is started, ready to run tests.'); |
||||
|
const testCmd = spawn('npm', ['run', 'jest'], { |
||||
|
stdio: 'inherit', |
||||
|
}); |
||||
|
testCmd.on('exit', () => { |
||||
|
startServer.kill(); |
||||
|
}); |
||||
|
} |
||||
|
}); |
||||
@ -0,0 +1,11 @@ |
|||||
|
import { jsdom } from 'jsdom'; |
||||
|
|
||||
|
// fixed jsdom miss
|
||||
|
const documentHTML = '<!doctype html><html><body><div id="root"></div></body></html>'; |
||||
|
global.document = jsdom(documentHTML); |
||||
|
global.window = document.defaultView; |
||||
|
global.navigator = global.window.navigator; |
||||
|
|
||||
|
global.requestAnimationFrame = global.requestAnimationFrame || function requestAnimationFrame(cb) { |
||||
|
return setTimeout(cb, 0); |
||||
|
}; |
||||
@ -0,0 +1 @@ |
|||||
|
module.exports = {}; |
||||
Loading…
Reference in new issue