question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Log-Messages from ComponentMock() on console when testing with Karma

See original GitHub issue

When I run ng test --watch, I get strange Log-Messages in the console:

 10% building modules 1/1 modules 0 active(node:13084) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
16 08 2018 09:20:43.637:INFO [karma]: Karma v2.0.4 server started at http://0.0.0.0:9888/
16 08 2018 09:20:43.637:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
16 08 2018 09:20:43.653:INFO [launcher]: Starting browser PhantomJS
16 08 2018 09:21:03.354:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on socket lxY65evuenL7JAXlAAAA with id 23197298
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 0 of 203 SUCCESS (0 secs / 0 secs)
LOG: 'Attempting to configure 'name' with descriptor '{"value":"MockOfGenericFormComponent"}' on object 'function ComponentMock() {
            var _this = this;
            this.registerOnChange = function (fn) { };
            this.registerOnTouched = function (fn) { };
            this.writeValue = function (value) { };
            (options.outputs || []).forEach(function (output) {
                _this[output.split(':')[0]] = new core_1.EventEmitter();
            });
LOG: 'Attempting to configure 'name' with descriptor '{"value":"MockOfGenericFormComponent"}' on object 'function ComponentMock() {
            var _this = this;
            this.registerOnChange = function (fn) { };
            this.registerOnTouched = function (fn) { };
            this.writeValue = function (value) { };
            (options.outputs || []).forEach(function (output) {
                _this[output.split(':')[0]] = new core_1.EventEmitter();
            });
        }' and got error, giving up: TypeError: Attempting to change value of a readonly property.'
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 0 of 203 SUCCESS (0 secs / 0 secs)
LOG: 'Attempting to configure 'name' with descriptor '{"value":"MockOfGenericFormComponent"}' on object 'function ComponentMock() {
            var _this = this;
            this.registerOnChange = function (fn) { };
            this.registerOnTouched = function (fn) { };
            this.writeValue = function (value) { };
            (options.outputs || []).forEach(function (output) {
                _this[output.split(':')[0]] = new core_1.EventEmitter();
            });
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 1 of 203 (skipped 202) SUCCESS (0.397 secs / 0.186 secs)
TOTAL: 1 SUCCESS
TOTAL: 1 SUCCESS
TOTAL: 1 SUCCESS

These strange logs appear on every component in our project. The spec file is just:

fdescribe('EntityEditorComponent', () => {
  let component: EntityEditorComponent;
  let fixture: ComponentFixture<EntityEditorComponent>;
  let store: Spy<ExtendedStore<any>>;

  beforeEach(async(() => {
    store = createSpyFromClass(ExtendedStore);

    // Spy Methods
    store.filterReducers.and.returnValue(Observable.empty());

    // TestBed Config
    TestBed.configureTestingModule({
      declarations: [
        EntityEditorComponent,
        MockComponent(GenericFormComponent)
      ],
      providers: [
        {provide: ExtendedStore, useValue: store}
      ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(EntityEditorComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});

Is there a chance to get rid of them? The tests obviously run nevertheless.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
jaaduscommented, Aug 21, 2018

I also get these logs when I try running tests using a MockComponent (Karma + PhantomJS)

0reactions
ike18tcommented, Oct 2, 2018

I’m going to close this issue since it is more of an issue with using PhantomJS which doesn’t support ES6.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Log-Messages from ComponentMock() on console when ...
I've tried to reproduce the issue with the ng-mocks tests by using the karma-phantom-launcher and including es6 polyfills, but I ended up ...
Read more >
How do I check for a console log in Karma/Jasmine?
Let's say I have this function I want to test: var test = function () ...
Read more >
How to test console output (console.log, console.warn) with ...
Let's suppose you want to create a React component to render an Error Message. You don't want to give any technical information to...
Read more >
Debugging tests - Testing Angular
Write debug output to the console using console.log , console.debug and friends. · Use the JavaScript debugger. You can either set breakpoints in ......
Read more >
Angular unit testing tutorial with examples - LogRocket Blog
Karma also ensures the result of the test is printed out either in the console or in the file log. By default, Angular...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found