本文整理汇总了TypeScript中@angular-devkit/schematics/testing.UnitTestTree.commitUpdate方法的典型用法代码示例。如果您正苦于以下问题:TypeScript UnitTestTree.commitUpdate方法的具体用法?TypeScript UnitTestTree.commitUpdate怎么用?TypeScript UnitTestTree.commitUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular-devkit/schematics/testing.UnitTestTree
的用法示例。
在下文中一共展示了UnitTestTree.commitUpdate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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\';/);
});
示例2: it
it('should be a noop if key is not found', () => {
const content = JSON.stringify({foo: 'bar'});
tree.create('tmp', content);
const ast = parseJsonAst(content) as JsonAstObject;
let recorder = tree.beginUpdate('tmp');
expect(() => removeKeyValueInAstObject(recorder, content, ast, 'hello')).not.toThrow();
tree.commitUpdate(recorder);
const value = tree.readContent('tmp');
expect(JSON.parse(value)).toEqual({foo: 'bar'});
expect(value).toBe('{"foo":"bar"}');
});
示例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;
}