Reputation: 599
I have a method that turn booleans into a Yes or No text
If true return 'Yes', if false return 'No', for example:
export const booleanToText = function (value) {
if (value === true) {
return 'Yes'
} else {
return 'No'
}
}
and I want to test this using JEST, but I think this is not the right way, what I have:
describe('booleanToText', () => {
it('should be able to turn boolean true to text Yes', () => {
const boolean = true
const text = 'Yes'
const booleanToText = boolean ? text : 'No'
expect(booleanToText).toEqual('Yes')
})
it('should be able to turn boolean false to text No', () => {
const boolean = false
const text = 'No'
const booleanToText = boolean ? text : 'Yes'
expect(booleanToText).toEqual('No')
})
})
Upvotes: 0
Views: 534
Reputation: 722
you have to first import your function.
and then use it like this expect(booleanToText(true)).toEqual("Yes")
so your test case would look like this:
import {booleanToText} from "yourPath"
// or if you re using just nodejs:
// const booleanToText = require("yourPath")
it('should be able to turn boolean true to text Yes', () => {
const boolean = true
const text = 'Yes'
expect(booleanToText(boolean)).toEqual('Yes')
})
Upvotes: 1