{"action":"opened","issue":{"url":"https://api.github.com/repos/angular/angular/issues/9017","repository_url":"https://api.github.com/repos/angular/angular","labels_url":"https://api.github.com/repos/angular/angular/issues/9017/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular/issues/9017/comments","events_url":"https://api.github.com/repos/angular/angular/issues/9017/events","html_url":"https://github.com/angular/angular/issues/9017","id":158492957,"number":9017,"title":"Testing: typings for `expect` should express Jasmine matchers (extended for Ng)","user":{"login":"wardbell","id":129061,"avatar_url":"https://avatars.githubusercontent.com/u/129061?v=3","gravatar_id":"","url":"https://api.github.com/users/wardbell","html_url":"https://github.com/wardbell","followers_url":"https://api.github.com/users/wardbell/followers","following_url":"https://api.github.com/users/wardbell/following{/other_user}","gists_url":"https://api.github.com/users/wardbell/gists{/gist_id}","starred_url":"https://api.github.com/users/wardbell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wardbell/subscriptions","organizations_url":"https://api.github.com/users/wardbell/orgs","repos_url":"https://api.github.com/users/wardbell/repos","events_url":"https://api.github.com/users/wardbell/events{/privacy}","received_events_url":"https://api.github.com/users/wardbell/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-06-04T07:41:19Z","updated_at":"2016-06-04T07:41:19Z","closed_at":null,"body":"* **I'm submitting a ...**\r\n- [x] bug report\r\n- [ ] feature request\r\n- [ ] support request => Please do not submit support request here, see note at the top of this template.\r\n\r\n**Current behavior**\r\n\r\n`expect` is typed as follows in `angular/core/testing/testing.ts`\r\n```\r\nexport var expect: Function = _global.expect;\r\n```\r\nThis means that we get no intellisense for `expect`\r\n\r\n**Expected/desired behavior**\r\nThe type definition should be this (which works)\r\n```\r\nexport declare function expect(spy: Function): NgMatchers;\r\nexport declare function expect(actual: any): NgMatchers;\r\n```\r\n### Discussion\r\n\r\n`expect` is the one item in the Jasmine test framework that has a rich API and should offer the developer type support. The others - `it`, `beforeEach`, etc - aren't chained and are too simple to require typing. We can live without typing support for them. But `expect` has a big API that's hard to remember.\r\n\r\nI suspect the source of the problem is that `expect` is exported from `@angular/core/testing` which defines a Jasmine-like api but has no Jasmine dependency.  I get that although, tbh, `expect`, `beforeEach`, etc are the Jasmine API, not anyone else's; other expectation libraries have a different API.\r\n\r\nWe have to go to `@angular/platform-browser/testing` to find the dependency on Jasmine. Not sure why it's OK here and not OK in `@angular/core`. Be that as it may, we should give the developer a version of `expect` with the full (extended) Jasmine API.\r\n\r\nIf the separation is still desired, then maybe we should invite the developer to get _all of the Angular/Jasmine members from `@angular/platform-browser/testing`_ rather than from `@angular/core/testing`.\r\n\r\n```\r\nimport {\r\n  beforeEach, beforeEachProviders,\r\n  describe, ddescribe, xdescribe,\r\n  expect,\r\n  it, iit, xit,\r\n} from '@angular/core/testing';\r\n```\r\n\r\n### Workaround\r\n\r\nMy ugly work around involves creating a file, `expect-proper.ts`, that produces an `expect` with typings and then importing `expect` from that module.\r\n\r\n```\r\n// expect-proper.ts\r\nimport { expect as expectCore} from '@angular/core/testing';\r\nimport { NgMatchers } from '@angular/platform-browser/testing';\r\n\r\nexport function expect(spy: Function): NgMatchers;\r\nexport function expect(actual: any): NgMatchers;\r\nexport function expect(actual: any): NgMatchers {\r\n  return expectCore(actual) as NgMatchers;\r\n}\r\n\r\n/*** usage ***/\r\n\r\n// Boilerplate\r\nimport {\r\n  beforeEach, beforeEachProviders,\r\n  describe, ddescribe, xdescribe,\r\n  it, iit, xit,\r\n  async, inject,\r\n  fakeAsync, tick, withProviders\r\n} from '@angular/core/testing';\r\n\r\nimport {expect} from './expect-proper';\r\n\r\n// Specs\r\n...\r\n    it('should use FancyService',\r\n      inject([FancyService], (service: FancyService) => {\r\n        expect(service.value).toEqual('real value');  // we now get intellisense for expect.\r\n    }));\r\n...\r\n```\r\n\r\n\r\n\r\n"}}
{"actor":{"display_login":"wardbell"}}