forked from b00tc4mp/isdi-bootcamp-202402
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function assert(value, target){ | ||
console.assert(value === target, value + ' equals ' + target) | ||
} | ||
|
||
function error(error, type, message){ | ||
console.assert(error.name === type, 'name') | ||
console.assert(error.message === message, 'message') | ||
} | ||
|
||
function instanceOf(value, type) { | ||
console.assert(value instanceof type === true, value + ' is instance of ' + type) | ||
} | ||
|
||
module.exports = { | ||
assert: assert, | ||
error: error, | ||
instanceOf: instanceOf | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
console.log('MATCHA 🍵') | ||
|
||
var matcha = {} | ||
var logs = [] | ||
|
||
function describe(title, callback){ | ||
logs[logs.length] = title | ||
console.log(title) | ||
|
||
callback() | ||
} | ||
|
||
function it(title, callback) { | ||
var log = '* ' + title | ||
|
||
logs[logs.length] = log | ||
console.log(log) | ||
|
||
callback() | ||
} | ||
|
||
function expect(value) { | ||
return { | ||
toBe: function (expected) { | ||
var matches = value === expected | ||
|
||
if (!matches) { | ||
var log = '❌ ' + value + ' to be ' + expected.name | ||
|
||
logs[logs.length] = log | ||
console.log(log) | ||
|
||
return false | ||
} | ||
log = '✅ ' + value + ' to be ' + expected.name | ||
|
||
logs[logs.length] = log | ||
console.info(log) | ||
|
||
return true | ||
} | ||
} | ||
} | ||
|
||
matcha.logs = logs | ||
matcha.describe = describe | ||
matcha.it = it | ||
matcha.expect = expect | ||
|
||
module.exports = matcha |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
var assert = require('./assert') | ||
var matcha = require('./matcha') | ||
|
||
console.log('matcha') | ||
|
||
|
||
|
||
console.log('> describe') | ||
|
||
matcha.logs.length = 0 | ||
var run = false | ||
|
||
assert.assert(!!matcha.describe, true) | ||
|
||
matcha.describe('describe title', function() { | ||
run = true | ||
}) | ||
|
||
assert.assert(run, true) | ||
assert.assert(matcha.logs[0], 'describe title') | ||
|
||
|
||
|
||
console.log('> it') | ||
|
||
matcha.logs.length = 0 | ||
run = false | ||
|
||
assert.assert(!!matcha.it, true) | ||
|
||
matcha.it('it title', function () { | ||
run = true | ||
}) | ||
|
||
assert.assert(run, true) | ||
assert.assert(matcha.logs[0], '* it title') | ||
|
||
|
||
|
||
console.log('> expect toBe (happy path)') | ||
|
||
assert.assert(!!matcha.expect, true) | ||
|
||
matcha.logs.length = 0 | ||
var result = matcha.expect(10).toBe(10) | ||
|
||
assert.assert(result, true) | ||
assert.assert(matcha.logs[0], '✅ 10 to be 10') | ||
|
||
|
||
|
||
console.log('< expect toBe (unhappy path)') | ||
|
||
matcha.logs.length = 0 | ||
result = matcha.expect(10).toBe(12) | ||
|
||
assert.assert(result, false) | ||
assert.assert(matcha.logs[0], '❌ 10 to be 12') |