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

@@ -1,6 +1,7 @@
import 'mocha';
import { expect } from 'chai';
import { FunctionCallArgument } from '@/application/Parser/Script/Compiler/Function/Call/Argument/FunctionCallArgument';
import { itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
import { testParameterName } from '../../../ParameterNameTestRunner';
describe('FunctionCallArgument', () => {
@@ -13,18 +14,20 @@ describe('FunctionCallArgument', () => {
.parameterName,
);
});
it('throws if argument value is undefined', () => {
// arrange
const parameterName = 'paramName';
const expectedError = `undefined argument value for "${parameterName}"`;
const argumentValue = undefined;
// act
const act = () => new FunctionCallArgumentBuilder()
.withParameterName(parameterName)
.withArgumentValue(argumentValue)
.build();
// assert
expect(act).to.throw(expectedError);
describe('throws if argument value is absent', () => {
itEachAbsentStringValue((absentValue) => {
// arrange
const parameterName = 'paramName';
const expectedError = `missing argument value for "${parameterName}"`;
const argumentValue = absentValue;
// act
const act = () => new FunctionCallArgumentBuilder()
.withParameterName(parameterName)
.withArgumentValue(argumentValue)
.build();
// assert
expect(act).to.throw(expectedError);
});
});
});
});

View File

@@ -2,18 +2,21 @@ import 'mocha';
import { expect } from 'chai';
import { FunctionCallArgumentCollection } from '@/application/Parser/Script/Compiler/Function/Call/Argument/FunctionCallArgumentCollection';
import { FunctionCallArgumentStub } from '@tests/unit/stubs/FunctionCallArgumentStub';
import { itEachAbsentObjectValue, itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
describe('FunctionCallArgumentCollection', () => {
describe('addArgument', () => {
it('throws if argument is undefined', () => {
// arrange
const errorMessage = 'undefined argument';
const arg = undefined;
const sut = new FunctionCallArgumentCollection();
// act
const act = () => sut.addArgument(arg);
// assert
expect(act).to.throw(errorMessage);
describe('throws if argument is missing', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const errorMessage = 'missing argument';
const arg = absentValue;
const sut = new FunctionCallArgumentCollection();
// act
const act = () => sut.addArgument(arg);
// assert
expect(act).to.throw(errorMessage);
});
});
it('throws if parameter value is already provided', () => {
// arrange
@@ -58,17 +61,17 @@ describe('FunctionCallArgumentCollection', () => {
});
});
describe('getArgument', () => {
it('throws if parameter name is undefined', () => {
// arrange
const expectedError = 'undefined parameter name';
const undefinedValues = ['', undefined];
for (const undefinedValue of undefinedValues) {
describe('throws if parameter name is absent', () => {
itEachAbsentStringValue((absentValue) => {
// arrange
const expectedError = 'missing parameter name';
const sut = new FunctionCallArgumentCollection();
const parameterName = absentValue;
// act
const act = () => sut.getArgument(undefinedValue);
const act = () => sut.getArgument(parameterName);
// assert
expect(act).to.throw(expectedError);
}
});
});
it('throws if argument does not exist', () => {
// arrange
@@ -94,17 +97,17 @@ describe('FunctionCallArgumentCollection', () => {
});
});
describe('hasArgument', () => {
it('throws if parameter name is undefined', () => {
// arrange
const expectedError = 'undefined parameter name';
const undefinedValues = ['', undefined];
for (const undefinedValue of undefinedValues) {
describe('throws if parameter name is missing', () => {
itEachAbsentStringValue((absentValue) => {
// arrange
const expectedError = 'missing parameter name';
const parameterName = absentValue;
const sut = new FunctionCallArgumentCollection();
// act
const act = () => sut.hasArgument(undefinedValue);
const act = () => sut.hasArgument(parameterName);
// assert
expect(act).to.throw(expectedError);
}
});
});
describe('returns as expected', () => {
// arrange