mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2024-06-17 04:30:41 +00:00
121 lines
3.4 KiB
JavaScript
121 lines
3.4 KiB
JavaScript
|
const { expect } = require('chai');
|
||
|
const { safeProperty } = require('../../lib/safe-property');
|
||
|
|
||
|
describe('# [unit-test]: safe-property.js', () => {
|
||
|
[
|
||
|
{
|
||
|
testCaseDescription: "standard test - string",
|
||
|
testCase: {
|
||
|
test: {
|
||
|
property1: "hello"
|
||
|
},
|
||
|
name: "property1",
|
||
|
type: "string",
|
||
|
defaultValue: undefined
|
||
|
},
|
||
|
expected: "hello"
|
||
|
},
|
||
|
{
|
||
|
testCaseDescription: "standard test - boolean",
|
||
|
testCase: {
|
||
|
test: {
|
||
|
property1: true
|
||
|
},
|
||
|
name: "property1",
|
||
|
type: "boolean",
|
||
|
defaultValue: undefined
|
||
|
},
|
||
|
expected: true
|
||
|
},
|
||
|
{
|
||
|
testCaseDescription: "standard test - boolean on null",
|
||
|
testCase: {
|
||
|
test: {
|
||
|
property1: null
|
||
|
},
|
||
|
name: "property1",
|
||
|
type: "boolean",
|
||
|
defaultValue: false
|
||
|
},
|
||
|
expected: false
|
||
|
},
|
||
|
{
|
||
|
testCaseDescription: "on null",
|
||
|
testCase: {
|
||
|
test: {
|
||
|
property1: null
|
||
|
},
|
||
|
name: "property1",
|
||
|
type: "string",
|
||
|
defaultValue: "hello"
|
||
|
},
|
||
|
expected: "hello"
|
||
|
},
|
||
|
{
|
||
|
testCaseDescription: "on empty string",
|
||
|
testCase: {
|
||
|
test: {
|
||
|
property1: ''
|
||
|
},
|
||
|
name: "property1",
|
||
|
type: "string",
|
||
|
defaultValue: "hello"
|
||
|
},
|
||
|
expected: "hello"
|
||
|
},
|
||
|
{
|
||
|
testCaseDescription: "on undefined",
|
||
|
testCase: {
|
||
|
test: {
|
||
|
property1: undefined
|
||
|
},
|
||
|
name: "property1",
|
||
|
type: "string",
|
||
|
defaultValue: "hello"
|
||
|
},
|
||
|
expected: "hello"
|
||
|
},
|
||
|
{
|
||
|
testCaseDescription: "on not mutch type",
|
||
|
testCase: {
|
||
|
test: {
|
||
|
property1: 1
|
||
|
},
|
||
|
name: "property1",
|
||
|
type: "string",
|
||
|
defaultValue: "hello"
|
||
|
},
|
||
|
expected: "hello"
|
||
|
},
|
||
|
{
|
||
|
testCaseDescription: "on object is null",
|
||
|
testCase: {
|
||
|
test: null,
|
||
|
name: "property1",
|
||
|
type: "string",
|
||
|
defaultValue: "hello"
|
||
|
},
|
||
|
expected: "hello"
|
||
|
},
|
||
|
{
|
||
|
testCaseDescription: "on object is undefined",
|
||
|
testCase: {
|
||
|
test: undefined,
|
||
|
name: "property1",
|
||
|
type: "string",
|
||
|
defaultValue: "hello"
|
||
|
},
|
||
|
expected: "hello"
|
||
|
},
|
||
|
].forEach((testItem) => {
|
||
|
it(`* ${testItem.testCaseDescription}`, () => {
|
||
|
const actual = safeProperty(
|
||
|
testItem.testCase.test,
|
||
|
testItem.testCase.name,
|
||
|
testItem.testCase.type,
|
||
|
testItem.testCase.defaultValue);
|
||
|
expect(actual).to.equal(testItem.expected);
|
||
|
});
|
||
|
})
|
||
|
})
|