From a1a09a59ab1cf5b23598cb63b8dce72d9a141209 Mon Sep 17 00:00:00 2001 From: Raymonzut <40148684+Raymonzut@users.noreply.github.com> Date: Sun, 19 Apr 2020 18:26:06 +0200 Subject: [PATCH] Update remote.js for vue-resource --- client/src/remote.js | 15 ++++++++++----- client/test/remote.js | 25 ------------------------- 2 files changed, 10 insertions(+), 30 deletions(-) delete mode 100644 client/test/remote.js diff --git a/client/src/remote.js b/client/src/remote.js index c5c78ce..b40df93 100644 --- a/client/src/remote.js +++ b/client/src/remote.js @@ -1,7 +1,12 @@ module.exports = { - postData: [ - { title: 'A walk in the park' }, - { title: 'Down the road', author: 'Alice' }, - { title: 'On a summer day', author: 'Bob' }, - ], + getPosts: function() { + this.$http + .get('http://localhost:5000/api/posts') + .then(res => { + this.posts = res.body + }) + .catch(err => { + console.log(`Error: ${err}`) + }) + }, } diff --git a/client/test/remote.js b/client/test/remote.js deleted file mode 100644 index 0fbb255..0000000 --- a/client/test/remote.js +++ /dev/null @@ -1,25 +0,0 @@ -const assert = require('chai').assert -const remote = require('../src/remote') - -describe('remote', () => { - const data = remote.postData - - describe('postData', () => { - it('should return an array', () => { - assert.typeOf(data, 'array') - }) - it('should not be empty', () => { - assert.isAtLeast(data.length, 1) - }) - it('should contain objects', () => { - for (obj of data) { - assert.typeOf(obj, 'object') - } - }) - it('should have objects with properties', () => { - for (obj of data) { - assert.isAtLeast(Object.keys(obj).length, 1) - } - }) - }) -})