Skip to content

Instantly share code, notes, and snippets.

@lmiller1990
Last active June 21, 2021 00:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmiller1990/8e17919503f119d656e96f55fccc4bc5 to your computer and use it in GitHub Desktop.
Save lmiller1990/8e17919503f119d656e96f55fccc4bc5 to your computer and use it in GitHub Desktop.
const describe = (desc, fn) => {
console.log(desc)
fn()
}
const it = (msg, fn) => describe(' ' + msg, fn)
const matchers = (exp) => ({
toBe: (asssertion) => {
if (exp === assertion) {
console.log('pass')
return true
} else {
console.log('fail')
return false
}
}
})
const expect = (exp) => matchers(exp)
function adder(a, b) {
return a + b
}
describe('adder', () => {
it('adds two numbers', () => {
const result = adder(1, 2)
expect(result).toBe(3)
})
})
module.exports = {
describe,
expect,
it,
matchers
}
@mohanramphp
Copy link

Amazing start for a wonderful test framework

@SumitBando
Copy link

asssertion ?

was this testing framework ever executed?

@lmiller1990
Copy link
Author

@SumitBando you can just put this in a JS file and run it with Node.js.

If you'd like to learn to build a testing framework with more features, check out this playlist I made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment