1

I am working in my local environment with clasp and typescript.

I read already this posts:

But that did not fully work out for me.

As in my (typescript) class I need to import as follows:

import CalendarApp = GoogleAppsScript.Calendar.CalendarApp
import Calendar = GoogleAppsScript.Calendar.Calendar

export default class someService{
...
}

When I do the test (in my doTests.test.ts typescript file) I try to mock GoogleAppScript as mentioned in one of the other postings:

// @ts-ignore
global.GoogleAppsScript = {
    // @ts-ignore
    Calendar: () => {
        CalendarApp: () => ({})
        Calendar: () => ({})
    }
}

test( ... ) //testing to create an instance of someService

And still getting the error:

● Test suite failed to run

    ReferenceError: GoogleAppsScript is not defined

    > 6 | import CalendarApp = GoogleAppsScript.Calendar.CalendarApp;
        |                      ^

What did I get wrong here?

UPDATE

What I also tried now, was to configure globals in the jest config:

globals: {
     GoogleAppsScript: {
       Calendar: {
           Calendar: () => {},
           CalendarApp: () => {}
         }
       }
   },

Now the problem was solved, but I am not sure if this was the right approach. If this gets more complex, and it will, I have I need to deal with that separation of mocks in the config.

Any best practice suggestions for that?

helle
  • 11,183
  • 9
  • 56
  • 83

0 Answers0