adopted-ember-addons / adopted-ember-addons/ember-data-model-fragments

Integration test: Uncaught TypeError: store.createFragment is not a function

Ouverte
#211 8 commentaires 0 réactions 1 personne assignée Réclamée par @workmanw Voir sur GitHub
Langage dominant
TypeScript
Étoiles
367
Forks
108
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

I am trying to write an integration test for a component that manipulates a model called `spot`.
Here is the spot model:

```
// models/spot.js

// imports...
// some validations rules...
const Validations = buildValidations({ ... });

export default Model.extend( Validations, {
customMeta : fragmentArray('custom-meta'),

name: attr("string"),

location: fragment('location', {
defaultValue: {
lat: null,
lon: null
}
}),

```

I am trying to create a spot record in such an integration test:

```
test('should render card displaying name, content, status correctly', function(assert) {
let spotMock;
const store = this.container.lookup('service:store');
run(()=>{
spotMock = store.createRecord('spot', {
isMoving: true,
name: 'spot-name',
// no matter whether the following is present or absent, the error persists
// location: store.createFragment('location', {
// lat: 1,
// lon: 1
// })
});
});
//...
```

`store.createRecord()` fails due to:
_Uncaught TypeError: store.createFragment is not a function_

This is the place which calls `store.createFragment()`:

```
// fragment.js

// Creates a fragment and sets its owner to the given record
function createFragment(store, declaredModelName, record, key, options, data) {
var actualModelName = getActualFragmentType(declaredModelName, options, data);
var fragment = store.createFragment(actualModelName); // error

setFragmentOwner(fragment, record, key);
setFragmentData(fragment, data);

return fragment;
}
```

Maybe a screenshot helps:
![createfragment](https://cloud.githubusercontent.com/assets/11027796/17922868/93e9d3d0-69e1-11e6-8532-b23fda0864b6.png)

Apparently, `createFragment()` is not set up upon the store yet. Do I have to set it up anyhow for the purposes of integration testing? I could not find any hint about it in the docs, however, I guess I am missing something simple in here.

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.