Array 'find' exception on undefined collection inside Module

I’m having an issue inside an Module where, if there is no data, I get an exception while calling the 'find` method on an array (inside function-extraction.js at the bottom):

TypeError: Cannot call method 'find' of undefined

On application start, of course there will be no userId, so the collection will be undefined. It’s only when an userId has been passed in from a Meteor method that the userId gets populated and the collections filled.

Example Code:

// imports/server/function-extraction.js

import Docs from './data-extraction'

// HERE `Test` will only be filled with data once the Meteor.Method is called.
const Test = Docs.test;

// HERE, even if I do a check if Test is undefined, it still throws:
export const GetTest = type => {
	if (Test.StringArrayType) {
		return Test.StringArrayType.find(thing => thing === type) ? 'Found it!' : '';
	}
}

UPDTE:

Check both Test and Test.StringArray and it no longer throws. :wink: Whereas before I was just checking for Test. Posted this too soon.

I updated the code to reflect the changes.