Skip to content

Instantly share code, notes, and snippets.

@artemave
Last active November 24, 2016 09:29
Show Gist options
  • Select an option

  • Save artemave/5b59c493d7f5d056d739a3a3e43f742c to your computer and use it in GitHub Desktop.

Select an option

Save artemave/5b59c493d7f5d056d739a3a3e43f742c to your computer and use it in GitHub Desktop.
import { expect } from 'chai';
export default function(browser) {
return browser.component({
fetchTODOsButton() {
return this.find('button');
},
loadingBar() {
return this.find('.loading', {text: 'Loading...'});
},
async expectTODOs(...expectedTodos) {
var actualTodos = (await this.find('ul li').elements())
.map(e => e.innerText);
expect(actualTodos.sort()).to.eql(expectedTodos.sort());
}
});
});
import createBrowser from 'browser-monkey/create';
import pageHelper from './pageHelper';
var browser, page;
beforeEach(() => {
browser = createBrowser(document.body);
page = pageHelper(browser);
});
it('allows user to fetch todos', async () => {
await page.fetchTODOsButton().click();
await page.loadingBar().shouldExist();
await page.expectTODOs('one', 'two');
});
import createBrowser from 'browser-monkey/create';
import pageHelper from './pageHelper';
var browser, page;
beforeEach(() => {
browser = createBrowser(document.body);
page = pageHelper(browser);
});
it('allows user to fetch todos', async () => {
await page.fetchTODOsButton().click();
await page.loadingBar().shouldExist();
await page.expectTODOs('one', 'two');
});
import createBrowser from 'browser-monkey/create';
var browser;
beforeEach(() => {
browser = createBrowser(document.body);
});
it('allows user to fetch todos', async () => {
// click button
await browser.find('button').click();
// observe "Loading..."
await browser.find('.loading', {text: 'Loading...'}).shouldExist();
// collect results from DOM
let actualTodos = (await browser.find('ul li').elements())
.map(e => e.innerText);
// assert results
expect(actualTodos.sort()).to.eql(['one', 'two'].sort());
});
module.exports = function(config) {
config.set({
frameworks: ['browserify', 'mocha'],
files: [
'test/**/*Spec.js'
],
preprocessors: {
'test/**/*.js': ['browserify']
},
browserify: {
debug: true,
transform: ['babelify'],
extensions: ['.jsx']
},
})
}
...
"scripts": {
"test-karma": "karma start --single-run",
"test-electron": "electron-mocha --renderer --compilers js:babel-core/register test/**/*Spec.js",
"test-vdom": "mocha --compilers js:babel-core/register test/**/*Spec.js"
},
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment