Skip to content

Instantly share code, notes, and snippets.

@taichi
Created October 31, 2018 09:04
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taichi/d000fa1eba03889be58bdf985c922f87 to your computer and use it in GitHub Desktop.
Save taichi/d000fa1eba03889be58bdf985c922f87 to your computer and use it in GitHub Desktop.
TypeScript + Jest + power-assert
import assert = require('assert');
it("hello", () => {
assert.equal({geeting:"WayWayWa", Fu:{Ho:1}},
{ greeting: "Hello", Fu:{Fe:1}});
});
PS C:\dev\js\projects\ts-test-examples> yarn test
yarn run v1.12.1
$ jest
FAIL ./hello.test.ts (9.167s)
× hello (22ms)
● hello
assert.equal(received, expected) or assert(received)
Expected value to be equal to:
{"Fu": {"Fe": 1}, "greeting": "Hello"}
Received:
{"Fu": {"Ho": 1}, "geeting": "WayWayWa"}
Message:
# hello.test.ts:4
assert.equal({ geeting: "WayWayWa", Fu: { Ho: 1 } }, { greeting: "Hello", Fu: { Fe: 1 } })
| | | |
| | | Object{Fe:1}
| Object{Ho:1} Object{greeting:"Hello",Fu:#Object#}
Object{geeting:"WayWayWa",Fu:#Object#}
Difference:
- Expected
+ Received
Object {
"Fu": Object {
- "Fe": 1,
+ "Ho": 1,
},
- "greeting": "Hello",
+ "geeting": "WayWayWa",
}
2 |
3 | it("hello", () => {
> 4 | assert.equal({geeting:"WayWayWa", Fu:{Ho:1}},
| ^
5 | { greeting: "Hello", Fu:{Fe:1}});
6 | });
7 |
at Decorator.Object.<anonymous>.Decorator._callFunc (node_modules/empower-core/lib/decorator.js:110:20)
at Decorator.Object.<anonymous>.Decorator.concreteAssert (node_modules/empower-core/lib/decorator.js:103:17)
at Function.decoratedAssert [as equal] (node_modules/empower-core/lib/decorate.js:49:30)
at Object.<anonymous> (hello.test.ts:4:10)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 9.375s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
{
"name": "ts-test-examples",
"version": "0.0.1",
"main": "index.js",
"author": "taichi",
"license": "MIT",
"private": true,
"devDependencies": {
"@babel/core": "^7.1.2",
"@types/jest": "^23.3.9",
"@types/node": "^10.12.1",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"babel-preset-power-assert": "^3.0.0",
"jest": "^23.6.0",
"power-assert": "^1.6.1",
"regenerator-runtime": "^0.12.1",
"ts-jest": "^23.10.4",
"typescript": "^3.1.4"
},
"scripts": {
"test": "jest"
},
"jest": {
"verbose": true,
"preset": "ts-jest",
"testEnvironment": "node",
"globals": {
"ts-jest": {
"babelConfig": {
"presets": [
"power-assert"
]
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment