Last active
March 3, 2017 19:39
-
-
Save bitttttten/b8e2803cdb828c617ec75ff7975234a3 to your computer and use it in GitHub Desktop.
transaction testing with Nightmare.js and chai template (pseudo code)
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| use the package.json file or do | |
| `npm i yargs nightmare chai -S` |
This file contains hidden or 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
| { | |
| "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" | |
| } | |
| } | |
This file contains hidden or 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
| 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