Stephan K.
Stephan K.

Reputation: 15732

Unit Test to see if class methods are defined

I simply want to test if my class methods are defined, e.g.:

export class GoalSettingsPage {

    public goal: Goal;

    constructor(
    ) {
        this.goal = this.navParams.get('goal');
    }

    saveForm(event) {
        this.viewCtrl.dismiss(this.goal);
    }

Unit Test sth like:

xit('should have methods defined', () => {

    let g = new Goal()
    let np = new NavParams()
    let vc = new ViewController()
    let e = new Events()
    let fb = new FormBuilder()

    let settingModal = new GoalSettingsPage(np,vc,fb,e);

    expect (settingModal.saveForm(e).toBeDefined;
})

Isn't working.

Upvotes: 0

Views: 995

Answers (1)

Estus Flask
Estus Flask

Reputation: 222855

To test the existence of a method in class instance it should be

expect(settingModal.saveForm).toBeDefined()

Or, more precisely,

expect(settingModal.saveForm).toBe(jasmine.any(Function));

Upvotes: 1

Related Questions