mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2024-05-25 19:58:09 +00:00
a4ee38540d
We bundle markdown-it-kroki, which can add mermaid diagrams to marp slides using https://kroki.io.
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);
|
|
});
|
|
})
|
|
})
|