diff --git a/packages/angular_devkit/schematics/src/tree/host-tree.ts b/packages/angular_devkit/schematics/src/tree/host-tree.ts index c37d9d11027d..8c4b012d401d 100644 --- a/packages/angular_devkit/schematics/src/tree/host-tree.ts +++ b/packages/angular_devkit/schematics/src/tree/host-tree.ts @@ -304,7 +304,12 @@ export class HostTree implements Tree { // With the `fatal` option enabled, invalid data will throw a TypeError return decoder.decode(data); } catch (e) { - if (e instanceof TypeError) { + // The second part should not be needed. But Jest does not support instanceof correctly. + // See: https://github.com/jestjs/jest/issues/2549 + if ( + e instanceof TypeError || + (e as NodeJS.ErrnoException).code === 'ERR_ENCODING_INVALID_ENCODED_DATA' + ) { throw new Error(`Failed to decode "${path}" as UTF-8 text.`); } throw e;