Last active
June 2, 2020 11:52
-
-
Save Swiip/d1079f4cdcfb56967ba61af12dcfa738 to your computer and use it in GitHub Desktop.
"Testing an AngularJS app with Jest" jest code samples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var localStorageMock = /* ... some mock code ... */ | |
Object.defineProperty(window, 'localStorage', { | |
value: localStorageMock | |
}); | |
import './app/index.module'; | |
import 'angular-mocks'; | |
import './app/mock/utils'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"jest": { | |
"testPathDirs": ["src"], | |
"setupTestFrameworkScriptFile": "src/jest.init.js" | |
} |
@lionelB Totally missed the notif sorry. If still relevant, here is some pseudo code of a test. Unfortunatly we had some factorization on mocking Angular injection.
import { ProductController } from './product.controller';
describe('controller: ProductController', () => {
beforeEach(mock.controller('ProductController', ProductController, ['pstates', '$ngRedux']));
beforeEach(function () {
this.scope = this.$rootScope.$new();
this.controller = this.$controller('ProductController', { $scope: this.scope });
this.scope.product = this.controller;
this.controller.$onInit();
});
it('should dispatch `LOAD_PRODUCT` action', function () {
expect(this.productActions.loadProduct).toHaveBeenCalledWith('p1');
});
});
Hey @Swiip, can you please share some light on the factorization on mocking Angular injection you've done here?.
Hallo @Swiip can you share a full project to check configs and creating bundles? I'm stucked now in my project by integration jest with ng1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Swiip I'm trying to migrate from jasmine to jest too but I couldn't find how to setup test properly. Initially, we ran test with the generated bundle. Could you point me to a small test case to see how import and test are written in the test ?