thardy / generator-ngbp

Yeoman generator based on the ngBoilerplate kickstarter, a best-practice boilerplate for any scale Angular project built on a highly modular, folder-by-feature structure.
100 stars 23 forks source link

Having issues mocking responses #36

Closed boroth closed 8 years ago

boroth commented 8 years ago

Disclaimer: I'm TERRIBLE at writing tests.

However, I'm trying to get better. I'm trying to test just with the samples you've given in mockApp.js, but it doesn't seem to be loading the whenGET interceptors? I'm not even sure this module is being loaded when my tests are being run, because I've added a console.log() into it and it's not spitting it out. I saw it one time, but haven't gotten it to run again.

Just trying to have the following http request mocked when i run grunt watchmock:

$http({
    method: 'GET',
    url: 'api/products'
}).success(function (data) {
    console.log(data);
    return data;
});

(this isn't the console.log i'm looking for, i added one to mockApp.js in the run block)

boroth commented 8 years ago

I only see my console.log when i explicitly add "mockApp" as a dependency to my app.js. I'm not sure where I should be including this dependency.

boroth commented 8 years ago

Figured it out, something was messed up with my jasmine/karma install.

thardy commented 8 years ago

Glad to hear it. I don't usually use grunt watchmock with actual automated tests. I usually use it when I'm manually testing or maybe with selenium tests that drive the browser, but I imagine it could work with those. With my automated tests, I'll usually mock closer to the test, like by injecting a fake service or something into the test that just returns some hardcoded json.