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

Test service with third party library #183

Closed
EugeneSnihovsky opened this issue Nov 29, 2016 · 4 comments
Closed

Test service with third party library #183

EugeneSnihovsky opened this issue Nov 29, 2016 · 4 comments

Comments

@EugeneSnihovsky
Copy link

Hi. Thanks again for your repo. It is very useful and saves time for me.
Can you help me, please, to test service with third party library (pouchDB)?

pouchDB has typings and it installed in node_modules/@types/pouchDB

App works correct, but when I try to test service with PouchDB I receive an error:

TypeError: pouchdb_1.default is not a constructor

And console.log show in terminal, that PouchDB is undefined. I think that test missing typings for pouchDB, but can't figure out how to include it correctly.

Service example:

'use strict';

import PouchDB from 'pouchdb';
import quickSearch from 'pouchdb-quick-search';
import PouchDbFind from 'pouchdb-find';

PouchDB.plugin(quickSearch);
PouchDB.plugin(PouchDbFind);

import { Injectable } from '@angular/core';
import { CONSTANTS } from '../../constants';

@Injectable()
export class PouchDbService {
    private animalsDb: any = new PouchDB(CONSTANTS.dataBaseName); // this line throw error
    private searchFields: string[] = ['DE_Name', 'EN_Name'];

    public search(query: string): Promise<any> {
        return this.animalsDb.search({
            query: query,
            include_docs: true,
            mm: '50%',
            fields: this.searchFields
        });
    }
}

I already ask it on ionic forum, but topic about tests has no action for a long time. I would be glad of any help. Thanks in advance.

@lathonez
Copy link
Owner

lathonez commented Nov 30, 2016 via email

@lathonez
Copy link
Owner

lathonez commented Dec 8, 2016

I'm not sure why you should get that error. I am testing pouch DB in a closed source project fine. However I have mocked pouch and initialise it a separate function so I spy and stub out when testing.

A good example of this is StorageService:

This issue #169 discusses the concept a bit.

However, I don't see how this would resolve the typings issue. IIRC, the typings for pouch were pretty fiddly?

Is your project open source (can I clone and replicate the issue)?

@lathonez
Copy link
Owner

lathonez commented Dec 9, 2016

Closing in favour or #191

@lathonez lathonez closed this as completed Dec 9, 2016
@alexlevy0
Copy link

@EugeneSnihovsky Did you find a solution? Thanks

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

No branches or pull requests

3 participants