Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not exist on type 'Matchers' #76

Closed
e11en opened this issue Jun 19, 2017 · 11 comments
Closed

Does not exist on type 'Matchers' #76

e11en opened this issue Jun 19, 2017 · 11 comments

Comments

@e11en
Copy link

e11en commented Jun 19, 2017

My tests keep failing because it can't find the matchers for some reason, am I missing something in the installation? I've also installed karma-jasmine-matchers but no luck.

I've added the following devDependencies:
"karma-jasmine-matchers": "^3.7.0"
"@types/jasmine": "2.5.45"
"@types/jasmine-matchers": "^0.2.30"
"jasmine-core": "~2.6.2"
"jasmine-expect": "^3.7.0"
"jasmine-spec-reporter": "~4.1.0"
"karma": "~1.7.0"
"karma-chrome-launcher": "~2.1.1"
"karma-cli": "~1.0.1"
"karma-coverage-istanbul-reporter": "^1.2.1"
"karma-jasmine": "~1.1.0"
"karma-jasmine-html-reporter": "^0.2.2"
"karma-jasmine-matchers": "^3.7.0"

karma.conf.js

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli', 'jasmine-matchers'],
    plugins: [
        'karma-jasmine',
        'karma-chrome-launcher',
        'karma-jasmine-html-reporter',
        'karma-coverage-istanbul-reporter',
        '@angular/cli/plugins/karma',
        'karma-jasmine-matchers'
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    angularCli: {
      environment: 'dev'
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

test.spec.ts

import { TestBed, async } from '@angular/core/testing';

import { CoreModule } from '../../core/core.module';
import { ExampleService } from '../../services/example.service';
import { ExampleComponent } from './example.component';

describe('ExampleComponent', () => {
    beforeEach(async(() => {
        TestBed.configureTestingModule({
            declarations: [
                ExampleComponent
            ],
            imports: [ CoreModule ],
            providers: [ ExampleService ]
        }).compileComponents();
    }));

    it('should create the example component', async(() => {
        const fixture = TestBed.createComponent(ExampleComponent);
        const app = fixture.debugElement.componentInstance;
        expect(app).toBeTruthy();
    }));

   // It fails here
    it('should be an array', async(() => {
        const test = [true, false, false, false];
        expect(test).toBeArrayOfBooleans();
    }));
});
@JamieMason
Copy link
Owner

Hi @e11en,
Sorry to hear you are having trouble, there is an example jasmine-matchers with karma setup available to check out, hopefully that will be of some help.

Thanks,

Jamie

@JamieMason
Copy link
Owner

JamieMason commented Jun 19, 2017

One thing I can see is: the items under plugins don't need to be require calls. Normally each plugin project specifies a string to use. For the Jasmine-Matchers plugin it is "karma-jasmine-matchers".

@e11en
Copy link
Author

e11en commented Jun 19, 2017

Hi @JamieMason,
I tried removing the required calls but that didn't change anything, the files of mine and those in the example were almost identical so that couldn't be it.

@e11en
Copy link
Author

e11en commented Jun 19, 2017

I tried removing and re-installing all the dependencies and even with the versions of the example, not luck.

@JamieMason
Copy link
Owner

If your code is the same as the working example, I'm afraid I don't have an answer that can help you. I notice you're using TypeScript though and – although I don't – I know @MiguelAngel82 @aaronbroad @ikasparov do and have commented on other TypeScript related issues – hopefully they can help you.

@e11en
Copy link
Author

e11en commented Jun 19, 2017

Ok, thanks for your helps so far and I'll wait for their response.
If necessary the full code base can be found here.

@mvaljento
Copy link

mvaljento commented Jun 21, 2017

@e11en , any luck so far?

I ran into similar trying to get "jasmine-expect" matchers to work with Protractor and it's driving me nuts. I've added references/require statements to karma.conf.js and protractor.conf.js, but the problem seems to be that TypeScript compiler does not recognise the custom matchers. When I run the tests with "ng e2e" I get same error:

expect(new Date()).toBeValidDate();

Error: TSError: ⨯ Unable to compile TypeScript e2e/public-events.e2e-spec.ts (39,24): Property 'toBeValidDate' does not exist on type 'Matchers<Date>'. (2339)

@e11en
Copy link
Author

e11en commented Jun 21, 2017

@mvaljento , nope I haven't figured it out yet.
I'm just waiting for the people that JamieMason tagged.

@JamieMason
Copy link
Owner

Did you get anywhere with this @e11en?

@JamieMason
Copy link
Owner

FAO TypeScript people, there is

  1. Some useful looking information from @davguij in TypeScript-based projects clues karma-jasmine-matchers#14 and @Types incorrect karma-jasmine-matchers#13
  2. A pull request about TypeScript at Add TypeScript declarations for typing #62
  3. A comment from me on the status of TypeScript in this project at Add TypeScript declarations for typing #62 (comment)

@JamieMason
Copy link
Owner

Closing due to inactivity, please reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants