[Unit test] jasmine createSpyObj

beforeEach(() => {
      contextStub = {
        debug: false,
        engine: jasmine.createSpyObj(‘engine‘, [
          ‘createCollection‘, ‘createContext‘, ‘createSchematic‘,
          ‘createSourceFromUrl‘, ‘transformOptions‘, ‘executePostTasks‘
        ]),
        logger: jasmine.createSpyObj(‘logger‘, [‘info‘]),
        schematic: jasmine.createSpyObj(‘schematic‘, [‘call‘]),
        strategy: 0,
        interactive: false,
        addTask: jasmine.createSpy()
      };
    });

    it(‘schedules an npm install task if Material is not installed‘, () => {
      const rule = installMaterial();
      rule(testTree, contextStub);

      expect(contextStub.addTask).toHaveBeenCalled();
      expect(contextStub.logger.info).toHaveBeenCalledWith(‘Installing Angular Material...‘);
    });

相关推荐