diff --git a/src/constants.ts b/src/constants.ts index bf4036663f..b18610f517 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,6 +2,8 @@ export const TEMPLATE_URL = 'templateUrl'; /** Angular component decorator styleUrls property name */ export const STYLE_URLS = 'styleUrls'; +/** Angular component decorator styleUrl property name */ +export const STYLE_URL = 'styleUrl'; /** Angular component decorator styles property name */ export const STYLES = 'styles'; /** Angular component decorator template property name */ diff --git a/src/transformers/replace-resources.ts b/src/transformers/replace-resources.ts index 32330e543d..3f62742eb4 100644 --- a/src/transformers/replace-resources.ts +++ b/src/transformers/replace-resources.ts @@ -8,7 +8,7 @@ import type { TsCompilerInstance } from 'ts-jest'; import ts from 'typescript'; -import { STYLES, STYLE_URLS, TEMPLATE_URL, TEMPLATE, REQUIRE, COMPONENT } from '../constants'; +import { STYLES, STYLE_URLS, TEMPLATE_URL, TEMPLATE, REQUIRE, COMPONENT, STYLE_URL } from '../constants'; const isAfterVersion = (targetMajor: number, targetMinor: number): boolean => { const [major, minor] = ts.versionMajorMinor.split('.').map((part) => parseInt(part)); @@ -225,12 +225,26 @@ function visitComponentMetadata( return nodeFactory.updatePropertyAssignment(node, nodeFactory.createIdentifier(TEMPLATE), importName); case STYLES: + if (!ts.isArrayLiteralExpression(node.initializer) && !ts.isStringLiteral(node.initializer)) { + return node; + } + + return undefined; + case STYLE_URLS: if (!ts.isArrayLiteralExpression(node.initializer)) { return node; } return undefined; + + case STYLE_URL: + if (!ts.isStringLiteral(node.initializer)) { + return node; + } + + return undefined; + default: return node; }