本文整理匯總了TypeScript中@angular-devkit/schematics/testing.UnitTestTree.beginUpdate方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript UnitTestTree.beginUpdate方法的具體用法?TypeScript UnitTestTree.beginUpdate怎麽用?TypeScript UnitTestTree.beginUpdate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@angular-devkit/schematics/testing.UnitTestTree
的用法示例。
在下文中一共展示了UnitTestTree.beginUpdate方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should throw error if property is not found', () => {
const content = JSON.stringify({});
tree.create('tmp', content);
const ast = parseJsonAst(content) as JsonAstObject;
const recorder = tree.beginUpdate('tmp');
expect(() => replacePropertyInAstObject(recorder, ast, 'foo', 'bar'))
.toThrowError(`Property 'foo' does not exist in JSON object`);
});
示例2: it
it('should not fail when AppModule have imported RouterModule already', () => {
const updateRecorder = appTree.beginUpdate('/projects/bar/src/app/app.module.ts');
updateRecorder.insertLeft(0, 'import { RouterModule } from \'@angular/router\';');
appTree.commitUpdate(updateRecorder);
const tree = schematicRunner.runSchematic('appShell', defaultOptions, appTree);
const filePath = '/projects/bar/src/app/app.module.ts';
const content = tree.readContent(filePath);
expect(content).toMatch(/import { RouterModule } from \'@angular\/router\';/);
});
示例3: runTest
function runTest(testFn: Function, obj: JsonValue, indent: number): string {
const content = JSON.stringify(obj, null, indent);
tree.create(filePath, content);
const ast = parseJsonAst(content);
const rec = tree.beginUpdate(filePath);
testFn(rec, ast);
tree.commitUpdate(rec);
const result = tree.readContent(filePath);
// Clean up the tree by deleting the file.
tree.delete(filePath);
return result;
}
示例4: runTest
function runTest(obj: Pojso, prop: string, val: string): Pojso {
const content = JSON.stringify(obj, null, 2);
tree.create(filePath, content);
const ast = parseJsonAst(content);
const rec = tree.beginUpdate(filePath);
if (ast.kind === 'object') {
insertPropertyInAstObjectInOrder(rec, ast, prop, val, 2);
}
tree.commitUpdate(rec);
const result = JSON.parse(tree.readContent(filePath));
// Clean up the tree by deleting the file.
tree.delete(filePath);
return result;
}