Skip to content

Instantly share code, notes, and snippets.

@bitttttten
Last active March 3, 2017 19:39
Show Gist options
  • Select an option

  • Save bitttttten/b8e2803cdb828c617ec75ff7975234a3 to your computer and use it in GitHub Desktop.

Select an option

Save bitttttten/b8e2803cdb828c617ec75ff7975234a3 to your computer and use it in GitHub Desktop.
transaction testing with Nightmare.js and chai template (pseudo code)
image: node:7.7.1
stages:
- test
before_script:
- npm set progress=false
- npm install > npm-install.log 2>&1
transaction testing:
stage: test
only:
- develop
script:
- node test.js --url=$URL
tags:
- docker
artifacts:
paths:
- npm-install.log
expire_in: 72 hrs
use the package.json file or do
`npm i yargs nightmare chai -S`
{
"name": "your project",
"version": "1.0.0",
"description": "chai and nightmare.js unit testing",
"dependencies": {
"primus": "*",
"async": "~0.8.0",
"express": "4.2.x",
"winston": "git://github.com/flatiron/winston#master",
"bigpipe": "bigpipe/pagelet",
"plates": "https://github.com/flatiron/plates/tarball/master"
}
}
const yargs = require('yargs').argv
const Nightmare = require('nightmare');
const should = require('chai').should();
// get the url from the cli argument
const { url } = yargs
describe('Transaction testing', () => {
// the form should at least be present
it('Should render the form', (done) => {
new Nightmare().goto(url)
.evaluate(
() => {
return document.querySelectorAll('form#formID').length
},
(result) => {
result.should.equal(1)
done()
})
.run()
})
// when entering in an incorrect card number
// make sure the "wrong card number" error is present
it('Should throw an error on wrong card number', (done) => {
new Nightmare().goto(url)
.type('input[name="card-number"]', '1234-AAAA-1234-1234-_#@!')
.click('input[type="submit"]')
.wait('.error') // wait until the element .error is present
.evaluate(
() => {
return document.querySelector('.error-message')
},
(result) => {
result.should.equal("wrong card number")
done()
})
.run()
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment