@@ -2,6 +2,7 @@ import fetchMock from "fetch-mock";
22import { getUserAgent } from "universal-user-agent" ;
33import { createActionAuth } from "@octokit/auth" ;
44
5+ import { OctokitOptions } from "../src/types" ;
56import { Octokit } from "../src" ;
67
78const userAgent = `octokit-core.js/0.0.0-development ${ getUserAgent ( ) } ` ;
@@ -90,7 +91,7 @@ describe("Octokit.defaults", () => {
9091 } ) ;
9192 } ) ;
9293
93- it ( "Octokit.defaults({auth})" , async ( ) => {
94+ it ( "Octokit.defaults({ auth })" , async ( ) => {
9495 const mock = fetchMock . sandbox ( ) . getOnce (
9596 "https://api.github.com/app" ,
9697 { id : 123 } ,
@@ -109,7 +110,7 @@ describe("Octokit.defaults", () => {
109110 } ;
110111
111112 const OctokitWithDefaults = Octokit . defaults ( {
112- auth : createActionAuth ( ) ,
113+ authStrategy : createActionAuth ,
113114 request : {
114115 fetch : mock
115116 }
@@ -149,7 +150,7 @@ describe("Octokit.defaults", () => {
149150 } ) ;
150151 } ) ;
151152
152- it ( "Octokit.plugins ().defaults()" , ( ) => {
153+ it ( "Octokit.plugin ().defaults()" , ( ) => {
153154 const mock = fetchMock . sandbox ( ) . getOnce (
154155 "https://github.acme-inc.test/api/v3/" ,
155156 { ok : true } ,
@@ -161,16 +162,31 @@ describe("Octokit.defaults", () => {
161162 }
162163 ) ;
163164
164- const OctokitWithDefaults = Octokit . plugin ( octokit => {
165- octokit . foo = "bar" ;
166- } ) . defaults ( {
165+ const OctokitWithPlugin = Octokit . plugin ( ( ) => {
166+ return {
167+ foo : "bar"
168+ } ;
169+ } ) ;
170+
171+ // See "A note on TypeScript" in README
172+ class OctokitWithPluginWorkaround extends OctokitWithPlugin {
173+ static defaults ( defaults : OctokitOptions ) {
174+ return class OctokitWithDefaults extends this {
175+ constructor ( options : OctokitOptions = { } ) {
176+ super ( Object . assign ( { } , defaults , options ) ) ;
177+ }
178+ } ;
179+ }
180+ }
181+
182+ const OctokitWithPluginAndDefaults = OctokitWithPluginWorkaround . defaults ( {
167183 baseUrl : "https://github.acme-inc.test/api/v3" ,
168184 request : {
169185 fetch : mock
170186 }
171187 } ) ;
172188
173- const octokit = new OctokitWithDefaults ( ) ;
189+ const octokit = new OctokitWithPluginAndDefaults ( ) ;
174190
175191 expect ( octokit . foo ) . toEqual ( "bar" ) ;
176192
0 commit comments