{"action":"created","issue":{"url":"https://api.github.com/repos/jasmine/jasmine/issues/1564","repository_url":"https://api.github.com/repos/jasmine/jasmine","labels_url":"https://api.github.com/repos/jasmine/jasmine/issues/1564/labels{/name}","comments_url":"https://api.github.com/repos/jasmine/jasmine/issues/1564/comments","events_url":"https://api.github.com/repos/jasmine/jasmine/issues/1564/events","html_url":"https://github.com/jasmine/jasmine/issues/1564","id":328919549,"node_id":"MDU6SXNzdWUzMjg5MTk1NDk=","number":1564,"title":"Question: How to use a custom matcher when using toHaveBeenCalledWith","user":{"login":"StefH","id":249938,"node_id":"MDQ6VXNlcjI0OTkzOA==","avatar_url":"https://avatars1.githubusercontent.com/u/249938?v=4","gravatar_id":"","url":"https://api.github.com/users/StefH","html_url":"https://github.com/StefH","followers_url":"https://api.github.com/users/StefH/followers","following_url":"https://api.github.com/users/StefH/following{/other_user}","gists_url":"https://api.github.com/users/StefH/gists{/gist_id}","starred_url":"https://api.github.com/users/StefH/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefH/subscriptions","organizations_url":"https://api.github.com/users/StefH/orgs","repos_url":"https://api.github.com/users/StefH/repos","events_url":"https://api.github.com/users/StefH/events{/privacy}","received_events_url":"https://api.github.com/users/StefH/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-06-04T06:07:21Z","updated_at":"2018-06-05T08:22:38Z","closed_at":null,"author_association":"NONE","body":"The following test-case verifies if the service (which uses Angular HttpClient to do a post request) does indeed use certain headers.\r\n\r\nI want to write some custom matching code to check if the headers contains a certain key and value, like:\r\n\r\n```js\r\nheaders.get('Session') === 'abc'\r\n```\r\n\r\nMy question is what to write at the **???** in below example?\r\n``` js\r\nspyOn(http, 'post').and.returnValue(new Observable<Response>());\r\n\r\nconst result = service.Post<string>(data);\r\n\r\nassert.isNotNull(result);\r\n\r\nexpect(http.post).toHaveBeenCalledWith(`http://localhost/odata/Employees`, jasmine.any(String),\r\n    {\r\n        headers: // ???,\r\n        observe: 'response'\r\n    });\r\n\r\n```\r\nIs this possible?"},"comment":{"url":"https://api.github.com/repos/jasmine/jasmine/issues/comments/394624331","html_url":"https://github.com/jasmine/jasmine/issues/1564#issuecomment-394624331","issue_url":"https://api.github.com/repos/jasmine/jasmine/issues/1564","id":394624331,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NDYyNDMzMQ==","user":{"login":"StefH","id":249938,"node_id":"MDQ6VXNlcjI0OTkzOA==","avatar_url":"https://avatars1.githubusercontent.com/u/249938?v=4","gravatar_id":"","url":"https://api.github.com/users/StefH","html_url":"https://github.com/StefH","followers_url":"https://api.github.com/users/StefH/followers","following_url":"https://api.github.com/users/StefH/following{/other_user}","gists_url":"https://api.github.com/users/StefH/gists{/gist_id}","starred_url":"https://api.github.com/users/StefH/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefH/subscriptions","organizations_url":"https://api.github.com/users/StefH/orgs","repos_url":"https://api.github.com/users/StefH/repos","events_url":"https://api.github.com/users/StefH/events{/privacy}","received_events_url":"https://api.github.com/users/StefH/received_events","type":"User","site_admin":false},"created_at":"2018-06-05T08:22:38Z","updated_at":"2018-06-05T08:22:38Z","author_association":"NONE","body":"Some documentation on this functionality, especially writing typescript code would indeed be helpfull.\r\n\r\nFor now I ended up with this matcher class:\r\n``` ts\r\nclass HttpHeadersMatcher {\r\n\r\n    constructor(private check: { [name: string]: string }) {\r\n    }\r\n\r\n    public asymmetricMatch(options: any): boolean {\r\n        const headers: HttpHeaders = options.headers;\r\n\r\n        assert.equal(options.observe, 'response');\r\n\r\n        Object.keys(this.check)\r\n            .forEach((key: string) => {\r\n                assert.equal(headers.get(key), this.check[key], `The header '${key}' does not have the correct value`);\r\n            });\r\n\r\n        return true;\r\n    }\r\n\r\n    public jasmineToString(): string {\r\n        return `<HeaderMatching: ${JSON.stringify(this.check)}>`;\r\n    }\r\n}\r\n```\r\n\r\nWhich is used like:\r\n``` ts\r\nexpect(http.post).toHaveBeenCalledWith(`http://localhost/odata/Employees`, jasmine.any(String), new HttpHeadersMatcher({ 'Session': 'abc' }));\r\n\r\n```\r\n\r\nMy project and example code can also be found here: [angular-odata-es5 : angularODataService.spec.ts](https://github.com/StefH/angular-odata-es5/blob/master/test/angularODataService.spec.ts#L13)\r\n\r\n\r\n"}}
{"actor":{"display_login":"StefH"}}