Skip to content

Commit e7dbce1

Browse files
committed
test(client:oauth): enable first new client test
1 parent 3244cbd commit e7dbce1

File tree

2 files changed

+54
-33
lines changed

2 files changed

+54
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
11
'use strict';
2+
import { ComponentFixture, TestBed } from '@angular/core/testing';
3+
import { By } from '@angular/platform-browser';
4+
import { DebugElement } from '@angular/core';
25

3-
import {OauthButtonsController} from './index';
6+
import { OauthButtonsComponent } from './oauth-buttons.component';
47

5-
describe('Controller: OauthButtonsController', function() {
8+
describe('Component: OauthButtonsComponent', () => {
9+
let comp: OauthButtonsComponent;
10+
let fixture: ComponentFixture<BannerComponent>;
11+
let de: DebugElement;
12+
let el: HTMLElement;
613

7-
var controller, $window;
14+
beforeEach(() => {
15+
TestBed.configureTestingModule({
16+
declarations: [ OauthButtonsComponent ], // declare the test component
17+
});
818

9-
beforeEach(() => {
10-
angular.module('test', [])
11-
.controller('OauthButtonsController', OauthButtonsController);
12-
});
13-
// load the controller's module
14-
beforeEach(angular.mock.module('test'));
19+
fixture = TestBed.createComponent(OauthButtonsComponent);
1520

16-
// Initialize the controller and a mock $window
17-
beforeEach(inject(function($controller) {
18-
$window = {
19-
location: {}
20-
};
21+
comp = fixture.componentInstance; // OauthButtonsComponent test instance
2122

22-
controller = $controller('OauthButtonsController', {
23-
$window: $window
23+
// query for the title <h1> by CSS element selector
24+
de = fixture.debugElement.query(By.css('a'));
25+
el = de.nativeElement;
2426
});
25-
}));
2627

27-
it('should attach loginOauth', function() {<% if (filters.jasmine) { %>
28-
expect(controller.loginOauth).toEqual(jasmine.any(Function));<% } if (filters.mocha) { %>
29-
<%= expect() %>controller.loginOauth<%= to() %>.be.a('function');<% } %>
30-
});
28+
it('test', () => {
29+
console.log(fixture.debugElement.query(By.css('i.fa-google-plus')));
30+
fixture.detectChanges();
31+
<%_ if (filters.jasmine) { -%>
32+
expect(el.textContent).toContain('Connect with Google+');
33+
<%_ } if (filters.mocha) { -%>
34+
<%= expect() %>el.textContent<%= to() %>.contain('Connect with Google+');
35+
<%_ } -%>
36+
});
3137
});

Diff for: templates/app/spec.js

+27-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
'use strict';
22
/*eslint-env node*/
3-
var testsContext;
4-
5-
require('babel-polyfill');
6-
require('angular');
7-
require('angular-mocks');
8-
<%_ if(filters.uirouter) { _%>
9-
require('./client/components/ui-router/ui-router.mock');<% } %>
10-
<%_ if(filters.socketio) { _%>
11-
require('./client/components/socket/socket.mock');<% } %>
12-
13-
testsContext = require.context('./client', true, /\.spec\.<%= scriptExt %>$/);
14-
testsContext.keys().forEach(testsContext);
3+
import 'babel-polyfill';
4+
5+
import 'zone.js/dist/zone';
6+
import 'zone.js/dist/long-stack-trace-zone';
7+
import 'zone.js/dist/proxy';
8+
import 'zone.js/dist/sync-test';
9+
// import 'zone.js/dist/jasmine-patch';
10+
import 'zone.js/dist/async-test';
11+
import 'zone.js/dist/fake-async-test';
12+
13+
var testsContext = require.context('./client', true, /\.(spec|test)\.<%= scriptExt %>$/);
14+
// testsContext.keys().forEach(testsContext);
15+
// testsContext('./app/main/main.component.spec.<%= scriptExt %>');
16+
testsContext('./components/oauth-buttons/oauth-buttons.component.spec.<%= scriptExt %>');
17+
18+
import { TestBed, getTestBed } from '@angular/core/testing';
19+
import browser from '@angular/platform-browser-dynamic/testing';
20+
21+
TestBed.initTestEnvironment(browser.BrowserDynamicTestingModule, browser.platformBrowserDynamicTesting());
22+
23+
var hook = new Mocha.Hook('Modified Angular beforeEach Hook', function() {
24+
getTestBed().resetTestingModule();
25+
});
26+
27+
hook.ctx = mocha.suite.ctx;
28+
hook.parent = mocha.suite;
29+
mocha.suite._beforeEach = [hook];

0 commit comments

Comments
 (0)