Add more and unify tests for absent object cases

- Unify test data for nonexistence of an object/string and collection.
- Introduce more test through adding missing test data to existing tests.
- Improve logic for checking absence of values to match tests.
- Add missing tests for absent value validation.
- Update documentation to include shared test functionality.
This commit is contained in:
undergroundwires
2022-01-21 22:34:11 +01:00
parent 0e52a99efa
commit 44d79e2c9a
100 changed files with 1380 additions and 976 deletions

View File

@@ -5,6 +5,7 @@ import { Script } from '@/domain/Script';
import { RecommendationLevel } from '@/domain/RecommendationLevel';
import { IScriptCode } from '@/domain/IScriptCode';
import { ScriptCodeStub } from '@tests/unit/stubs/ScriptCodeStub';
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
describe('Script', () => {
describe('ctor', () => {
@@ -20,18 +21,20 @@ describe('Script', () => {
// assert
expect(actual).to.deep.equal(expected);
});
it('throws if undefined', () => {
// arrange
const name = 'script-name';
const expectedError = `undefined code (script: ${name})`;
const code: IScriptCode = undefined;
// act
const construct = () => new ScriptBuilder()
.withName(name)
.withCode(code)
.build();
// assert
expect(construct).to.throw(expectedError);
describe('throws when missing', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const name = 'script-name';
const expectedError = `missing code (script: ${name})`;
const code: IScriptCode = absentValue;
// act
const construct = () => new ScriptBuilder()
.withName(name)
.withCode(code)
.build();
// assert
expect(construct).to.throw(expectedError);
});
});
});
describe('canRevert', () => {
@@ -114,7 +117,7 @@ class ScriptBuilder {
private level = RecommendationLevel.Standard;
private documentationUrls: readonly string[] = undefined;
private documentationUrls: readonly string[];
public withCodes(code: string, revertCode = ''): ScriptBuilder {
this.code = new ScriptCodeStub()