ngrx-workshop
  • Table of Contents
  • Setup and Configuration
  • Rules of Thumb
  • Rules of Thumb pt2
  • NgRx Libraries
    • NgRx Data
    • NgRx Entity
    • Action Creators
    • NgRx Auto Entity
  • NgRx Facades
    • NgRx Facades
  • Testing
    • Testing Factory
    • Testing Reducers
    • Testing Selectors
    • Testing Effects
  • Advanced Actions
    • 3 Types of Actions
    • Deciders
    • Splitter Actions
    • Aggregators
  • ToDo
    • Todo
Powered by GitBook
On this page

Was this helpful?

  1. Testing

Testing Factory

// State Factory
const createUser = ({
 id = 0,
 firstName = '',
 lastName = '',
 userName = ''
} = {}): User => ({
 id: id,
 firstName: firstName || 'firstName',
 lastName: lastName || `lastName`,
 userName: userName || `${firstName}.${lastName}`
});

const createUsersState = ({
entities = {
'1': createUser({ id: 1, firstName: 'Bob' }), 
'2': createUser({ id: 2, firstName: 'Sue' }), 
'3': createUser({ id: 3, firstName: 'Mary' })
 	},
 	ids = ['1', '2', '3'], 
selectedId = 0, 
loading = false, 
error = ''
} = {}) => ({
 users: {
   ids,
   entities,
   selectedId,
   loading,
   error
 }
});	
PreviousNgRx FacadesNextTesting Reducers

Last updated 5 years ago

Was this helpful?