Skip to content

Instantly share code, notes, and snippets.

View patoi's full-sized avatar
👀
...

István Pató patoi

👀
...
View GitHub Profile
it('is OK - not bad', async () => {
let result = await testFunction(true)
expect(result).to.be.equal('OK')
// flawed test throws an error, but it is not a test error (AssertionError)
})
it('is not OK - not bad, but it could be better', async () => {
try {
let result = await testFunction(false)
expect.fail()
// flawed test throws an ugly error:
} catch (err) {
// ...'AssertionError: expected 'expect.fail()' to equal 'not OK''
expect(err.message).to.be.equal('not OK')
}
})
it('is not OK - bad!', async () => {
try {
let result = await testFunction(false)
// flawed tests __pass__ instead of throws an error!
} catch (err) {
expect(err.message).to.be.equal('not OK')
}
})
@patoi
patoi / code.js
Last active April 3, 2018 09:10
Testing async/await
async function testFunction (isOK) {
if (isOK === true) {
return 'OK'
} else {
throw new Error('not OK')
}
}
it('is not OK - better way', async function() {
let result, error
try {
result = await testFunction(false)
} catch (err) {
error = err
} finally {
expect(result).to.be.undefined() // guard: handling code flaw
expect(error.message).to.be.equal('not OK')
}
it('is OK - better way', async function() {
let result, error
try {
result = await testFunction(true)
} catch (err) {
error = err
} finally {
expect(error).to.be.undefined() // guard: handling code flaw
expect(result).to.be.equal('OK')
}
it('your test', async function() {
let args = ... // your test data
let result, error // variables: test and guard in the finally block
try {
result = await testFunction(args)
} catch (err) {
error = err
} finally {
@patoi
patoi / WebDriver_Mocha
Last active April 9, 2018 03:16
Selenium WebDriver JavaScript test with Mocha and NodeJS
/*
* Selenium WebDriver JavaScript test with Mocha and NodeJS
*
* Start with: SELENIUM=PATH_TO_SELENIUM_JAR/selenium-server-standalone-2.31.0.jar mocha -t 10000 -R list google-sample.js
*
* Download selenium-server-standalone-2.31.0.jar from https://selenium.googlecode.com/files/selenium-server-standalone-2.31.0.jar
* 'sudo su' and 'npm install -g colors mocha selenium-webdriver'
*
* http://visionmedia.github.io/mocha/
* https://code.google.com/p/selenium/wiki/WebDriverJs
FROM node:8-alpine
# the client version we will download from bumpx repo
ENV CLIENT_FILENAME instantclient-basic-linux.x64-12.1.0.1.0.zip
# work in this directory
WORKDIR /opt/oracle/lib
# take advantage of this repo to easily download the client (use it at your own risk)
ADD https://github.com/bumpx/oracle-instantclient/raw/master/${CLIENT_FILENAME} .
'use strict'
const ITERATION = 1000
console.log(
process.version,
ITERATION,
'iteration',
'with Type and freeze – v2: prototype based constructor function'
)