Commit d2b362b9 authored by Paul Slaughter's avatar Paul Slaughter

Fix axios automatically parsing snippet content

This caused JSON values to not be loaded properly
parent 92bb931d
......@@ -53,7 +53,10 @@ export default {
const url = joinPaths(baseUrl, this.blob.rawPath);
axios
.get(url)
.get(url, {
// This prevents axios from automatically JSON.parse response
transformResponse: [f => f],
})
.then(res => {
this.notifyAboutUpdates({ content: res.data });
})
......
---
title: Fix snippets edit not loading JSON values
merge_request: 40417
author:
type: fixed
......@@ -17,6 +17,7 @@ const TEST_PATH = 'foo/bar/test.md';
const TEST_RAW_PATH = '/gitlab/raw/path/to/blob/7';
const TEST_FULL_PATH = joinPaths(TEST_HOST, TEST_RAW_PATH);
const TEST_CONTENT = 'Lorem ipsum dolar sit amet,\nconsectetur adipiscing elit.';
const TEST_JSON_CONTENT = '{"abc":"lorem ipsum"}';
const TEST_BLOB = {
id: TEST_ID,
......@@ -66,7 +67,7 @@ describe('Snippet Blob Edit component', () => {
});
describe('with not loaded blob', () => {
beforeEach(async () => {
beforeEach(() => {
createComponent();
});
......@@ -100,6 +101,20 @@ describe('Snippet Blob Edit component', () => {
});
});
describe('with unloaded blob and JSON content', () => {
beforeEach(() => {
axiosMock.onGet(TEST_FULL_PATH).reply(200, TEST_JSON_CONTENT);
createComponent();
});
// This checks against this issue https://gitlab.com/gitlab-org/gitlab/-/issues/241199
it('emits raw content', async () => {
await waitForPromises();
expect(getLastUpdatedArgs()).toEqual({ content: TEST_JSON_CONTENT });
});
});
describe('with error', () => {
beforeEach(() => {
axiosMock.reset();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment