Created
November 3, 2023 22:13
-
-
Save isaacbatst/f26110b871ec1e4d97d28c5f97d6e4d5 to your computer and use it in GitHub Desktop.
Tests if uses destructuring
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
const test = require('node:test') | |
const assert = require('assert') | |
// object | |
// description | |
// write a function that receives an object, destructure a property "name" and returns it | |
// destructure({ name: 'Zambs' }) // returns Zambs | |
// solution | |
function destructureObj({name}) { | |
return name | |
} | |
test('should return name', () => { | |
assert.strictEqual(destructureObj({name: 'Zambs'}), 'Zambs') | |
}) | |
test('should not have dots', () => { | |
const stringfied = destructureObj.toString(); | |
const chars = stringfied.split('') | |
const hasDots = chars.some(char => char === '.') | |
assert.strictEqual(hasDots, false) | |
}) | |
// array | |
// description | |
// write a function that receives an array, destructure the first element and returns it | |
// destructure(['Zambs']) // returns Zambs | |
// solution | |
function destructureArray([element]) { | |
return element | |
} | |
test('should return name', () => { | |
assert.strictEqual(destructureArray(['Zambs']), 'Zambs') | |
}) | |
test('should not mention zero index', () => { | |
const stringfied = destructureArray.toString(); | |
const chars = stringfied.split('') | |
const doesMentionZeron = chars.some(char => char === '0') | |
assert.strictEqual(doesMentionZeron, false) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment