Skip to content

Commit

Permalink
fix: update fhg-jest
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Apr 22, 2024
1 parent 1b5f94b commit 6db33c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
*****************************************************************************/

import { describe, beforeEach, it, expect, jest } from '@jest/globals';
import { createSpyObj } from 'fhg-jest';
import { Logger } from '../../../app/logging/logger.js';
import { OpcuaReader } from '../../../app/packages/opcua/opcua-reader.js';
import { OPCUAComponent } from '../../../app/packages/opcua/opcua.js';
import { OpcuaDataTypeDictionary } from '../../../app/packages/opcua/opcua-data-type-dictionary.js';
import { createSpyObj } from 'fhg-jest';

describe('OpcuaReader', function () {
describe('OpcuaReader', () => {
let reader: OpcuaReader;
let logger: jest.Mocked<Logger>;
let origin: jest.Mocked<OPCUAComponent>;
let dataTypes: jest.Mocked<OpcuaDataTypeDictionary>;

beforeEach(function () {
beforeEach(() => {
logger = createSpyObj<Logger>(['error', 'warning', 'info', 'debug', 'start', 'stop']);
origin = createSpyObj<OPCUAComponent>({}, ['displayName', 'hasProperty', 'nodeClass']);
dataTypes = createSpyObj<OpcuaDataTypeDictionary>(['get']);
reader = new OpcuaReader(logger, origin, dataTypes);
});

it('should be created', function () {
it('should be created', () => {
expect(reader).toBeTruthy();
});
});
4 changes: 3 additions & 1 deletion projects/fhg-jest/src/lib/create-spy-obj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export function createSpyObj<T extends object>(

if (propertyNames) {
if (Array.isArray(propertyNames)) {
throw new Error('Not implemented.');
for (const propertyName of propertyNames) {
obj[propertyName] = propertyNames[propertyName];
}
} else {
for (const propertyName in propertyNames) {
obj[propertyName] = propertyNames[propertyName];
Expand Down

0 comments on commit 6db33c2

Please sign in to comment.